Just as a test, I have set up two cubes. One that when clicked, turns red and sets a private variable "isActive" to false, and if clicked again, turns green and sets "isActive" to true.
Code for parent object:
private var isActive = false;
function OnMouseUp ()
{
if (isActive == false)
{
isActive = true;
}
else
{
isActive = false;
}
}
function Update ()
{
if (isActive == false)
{
renderer.material.color = Color.red;
}
else
{
renderer.material.color = Color.green;
}
}
The other cube is supposed to turn yellow when hovered over by the mouse only if the "isActive" variable of the parent is true.
Here's the code for the child object:
function OnMouseOver ()
{
//"parentObject" is another game object that actually holds the "isActive" variable.
if (parentObject.isActive == true)
renderer.material.color = Color.yellow;
}
function OnMouseExit ()
{
renderer.material.color = Color.white;
}
I know the 4th line of the child's code is wrong, i just put it there to show you what I'm going for. Is there a command or line of code that can read the variable from its parent without having to specifically define the name of the parent object?