I made 2 scripts and assigned it to 2 cubes: "cube" and "cube 1". Normally if you click on cube it sets a value so that when you click cube 1 it disappears. If you click cube 1 first it's not gonna work. So that's what I tried to make but it does not work and I don't understand why.
here are my scripts
cube:
using UnityEngine; using System.Collections; public class script : MonoBehaviour { public int test = 0; // make the variable for the value public void OnMouseDown() // when the user click { test = 1; //make the value of test 1 } } cube 1:
using UnityEngine; using System.Collections; public class NewBehaviourScript1 : MonoBehaviour { public GameObject a; //make a gameobject public script script; //make a variable where we put in the script void OnMouseDown() // when the user click { script = a.GetComponent<script>(); // get script if ( script.test == 1) //test or the variable test in the other script is 1 { Destroy(gameObject); // destroy the object } } } Can someone please help me?