Question by
Pnm279 · May 05, 2016 at 02:24 AM ·
script error
How to reference this game object to another class
Hi all!
I have a Game Master script wich i want to store in a variable the last clicked object.
public class GameMaster : MonoBehaviour {
public static GameObject sElectedobject;
void Update()
{
if (sElectedobject!= null)
Debug.Log(""+sElectedobject.name);
}
}
Of course i have a script in the object im clicking wich should refer himself to GameMaster class as the new value to this sElectedobject variable.
void OnMouseDown()
{
if (bSeleccionado == false)
{
bSeleccionado = true;
GameMaster.sElectedobject= GetComponent<GameObject>();
}
//Here im saving the Gameobject component to the variable.
This doesnt work, the variable in Game Master doesnt changes, it like im doing bad the self gameobject reference on my Click script or something... wich is the right way to do so?
Comment