|
- void OnDisable()
- {
- if(gameObject.active)
- {
- if(isMouse==true)
- {
- Object pigDeadObj;
- pigDeadObj=Instantiate(pigDead,transform.position,transform.rotation);
- }
- }
- else
- {
- 在此处不可使用GameObject[] holeObjs1 = GameObject.FindGameObjectsWithTag("Hole"); find等方法
- }
-
- }
复制代码 解决方法:- void Start()
- {
- Invoke("CRandomPig",2.5F);
- }
复制代码 把销毁对象放在find方法后:- void CRandomPig()
- {
- GameObject[] holeObjs1 = GameObject.FindGameObjectsWithTag("Hole");
- int i=Random.Range(0,holeObjs1.Length);
- Object clonePig2=Instantiate(me,new Vector3(holeObjs1[i].transform.position.x-0.9f,holeObjs1[i].transform.position.y,2.1f),holeObjs1[i].transform.rotation);
- GameObject [] pigObjs1=GameObject.FindGameObjectsWithTag("Pig");
- int j=Random.Range(0,i);
- if(pigObjs1.Length<=5)
- {
- Object clonePig3=Instantiate(me,new Vector3(holeObjs1[j].transform.position.x-0.9f,holeObjs1[j].transform.position.y,2.1f),holeObjs1[j].transform.rotation);
- }
- isMouse=false;
- Destroy(gameObject);
- }
复制代码 在void OnDisable()添加if(isMouse==true)- void OnDisable()
- {
- if(gameObject.active)
- {
- if(isMouse==true)
- {
- Object pigDeadObj;
- pigDeadObj=Instantiate(pigDead,transform.position,transform.rotation);
- }
- }
- else
- {
-
- }
- }
复制代码 |
|