Hello.
I hope you can help me.
I am trying to disappear an object when I click another one.
I want to distinguish between two different objects.
This is my code, but it doesn’t work out.
Is this script attached to both GameObjects in the editor? Otherwise the script isn’t running
In order for this to work you’d have to go to each GameObject’s inspector in the editor and fill the two variables with GameObjects. Otherwise the dogGP2 and boyGP2 variables will be blank.
Another way to solve the second tip is to define the variables at scene start like below:
// Attach this script to both objects
public GameObject boyGP2, dogGP2;
void Start() {
boyGP2 = GameObject.Find("boyGP2");
dogGP2 = GameObject.Find("dogGP2");
}
void OnMouseDown() {
if(gameObject.name=="boyGP2"){
Destroy(dogGP2);
}
if(gameObject.name=="dogGP2"){
Destroy(boyGP2);
}
}
I always code in UnityScript, but I’m pretty sure I got something as simple as this right.