欢迎大家来到我的博客http://unity.gopedu.com/home.php?mod=space&uid=3352&do=blog&view=me&from=space
今天做了老鼠死亡自动生成在它自己本来所在的位置(笔者的每个老鼠的脚本都不一样,所以写比较麻烦一点,读者可写成一样,会容易操作一些)
public GameObject[] mouse;//拖入要生成的老鼠组
string dieMouseName;
float mouseTime=4;//老鼠生成的时间间隔
void Start () {
}
void GetMouseName(string name) {
dieMouseName = name;//从另一个脚本接受死亡老鼠的名字,用于克隆死亡的老鼠
}
void Update () {
if (Mouse_Number.mouseNumber<5)//保证老鼠的总数在5个
{
mouseTime-=Time.deltaTime;
if(mouseTime<=0){
if (dieMouseName == "Mouse1" || dieMouseName == "Mouse1(Clone)")//克隆的预设体名字后会自动加上(Clone)
{
GameObject mouse1 = GameObject.Instantiate(mouse[0], transform.TransformPoint(new Vector3(-1.803148f, 6.99492f, -3.670626f)), Quaternion.identity) as GameObject;
Mouse_Number.mouseNumber++;
mouseTime = 4;
}
else if (dieMouseName == "Mouse2" || dieMouseName == "Mouse2(Clone)")
{
GameObject mouse2 = GameObject.Instantiate(mouse[1], transform.TransformPoint(new Vector3(-1.108377f, 6.994919f, -4.78252f)), Quaternion.identity) as GameObject;
Mouse_Number.mouseNumber++;
mouseTime = 4;
}
else if (dieMouseName == "Mouse3" || dieMouseName == "Mouse3(Clone)")
{
GameObject mouse3 = GameObject.Instantiate(mouse[2], transform.TransformPoint(new Vector3(0.9038711f, 6.994919f, -5.041567f)), Quaternion.identity) as GameObject;
Mouse_Number.mouseNumber++;
mouseTime = 4;
}
else if (dieMouseName == "Mouse4" || dieMouseName == "Mouse4(Clone)")
{
GameObject mouse4 = GameObject.Instantiate(mouse[3], transform.TransformPoint(new Vector3(-1.138228f, 6.994918f, -7.336784f)), Quaternion.identity) as GameObject;
Mouse_Number.mouseNumber++;
mouseTime = 4;
}
}
}
}
请继续关注我的博客
http://unity.gopedu.com/home.php?mod=space&uid=3352&do=blog&view=me&from=space
更多精彩尽在 http://www.gopedu.com/