So I have two scripts each attached to a few blocks (gameObjects).
Scripts are: DragScript and CheckWin
DragScript actually enables the CheckWin script when the gameobject its attached to is clicked.
public class DragScript : MonoBehaviour {
public CheckWin scriptCheckWin;
public static bool mySwitch = true;
void OnMouseDown()
{
if (Physics.Raycast(ray, out rayHit))
{
if (rayHit.collider.tag == "Puzzle")
{
scriptCheckWin = gameObject.GetComponent<CheckWin>();
if (mySwitch == true)
{
scriptCheckWin.enabled = true;
mySwitch = false;
}
else {
scriptCheckWin.enabled = false;
mySwitch = true;
}
}
}
}
This lets me turn enable and disable the scriptCheckWin on the gameObject -by clicking it- the dragscript is attached to (like it should)
The problem is if I click another gameobject its scriptCheckWin is enabled and the previous one I just clicked is also enabled. I only want one scriptCheckWin to be enabled when clicked to be enabled for efficiency. Just to let you know there will be more than 2 gameobjects.
Thanks in advance.