- Home /
Detect when instance has deleted
here I am with yet another problem. Have patience but they are starting out with unity scrip. The game that I want to do is to click on color blue balls falling randomly from above. Falling change color in difficulty putting the player. I was able to tell the script that every time the ball is blue, you can delete it using OnMouseDown (); Now I want every time you click the blue ball is increased the score. Except that since all instances must apply the script to the Main Camera. This was my idea, but obviously does not work. Tips? thanks to all.
var speed : int = 2; var chrismasBall : GameObject; //GameObject var instanza:GameObject[]; //instanza //var texBall : Texture[] = new Texture [5]; //Array di texture
var score : int = 0;
function Start () {
StartCoroutine(Creation(1)); //Coroutine
}
function Update () { //Physics.gravity = Vector3(0, -0.05, 0); // aggiungo gravità
trova = GameObject.Find("Sphere(Clone)"); if(trova == null){ score +=1; print("Cancellato"); }
}
function Creation(tempo){
while(true){ //finchè è vero esegui il ciclo
var posizione : Vector3 = Vector3 (Random.Range(-1.3,1.3),2,2); var pallaNuova : int = Random.Range(0,instanza.length-1); Instantiate (instanza[pallaNuova], transform.position+posizione, Quaternion.identity); //instanza chrismasBall
//instanza.AddComponent(Rigidbody); //aggiungo rigidbody alle instanze
/*
instanza.transform.position.x = Random.Range(2,-2); //raggio di instanza
instanza.transform.position.y = 2;
instanza.transform.position.z = 0.2; //distanza dalla Main Camera
instanza.transform.Translate(0, Time.deltaTime, 0);
*/
yield WaitForSeconds(tempo);
}
}
Your answer
Follow this Question
Related Questions
Combine objects instantiated at runtime 2 Answers
Instantiate as child 3 Answers
Get transform of an instantiated GameObject(clone) 1 Answer
AddComponent() causes a "trying to create a MonoBehaviour using the 'new' keyword" warning 2 Answers
GameManager class doesn't accept GameObject.Find() 0 Answers