Hey I need your help guys.
Can you tell me if GameObject.Find is called when The Game Only Starts or when you want it.
Cuz Im searching for some gameObjects, and they are not found
public Vector3 blueScale;
public Vector3 orangeScale;
public Vector3 yellowScale;
public Vector3 purpleScale;
public Vector3 greenScale;
public Vector3 redScale;
public float blueEnergy;
public float greeEnergy;
public float orangeEnergy;
public float purpleEnergy;
public float redEnergy;
public float yellowEnergy;
public Transform blue ;
public Transform green;
public Transform orange;
public Transform purple;
public Transform red;
public Transform yellow;
public GameObject _blue;
public GameObject _green;
public GameObject _orange;
public GameObject _purple;
public GameObject _red;
public GameObject _yellow;
void Start()
{
FindItemsObjects (out _blue);
}
void Update()
{
//Debug.Log (_blue);
}
void OnGUI()
{
if(GUI.Button(new Rect(10,120,100,50), "New Level"))
{
FindItemsObjects(out _blue);
}
}
public void FindItemsObjects(out GameObject _sds)
{
Debug.Log ("Here Im searching");
_sds = GameObject.FindWithTag ("Blue");
WhenYouDoSomething (_sds, out blue, out blueScale);
Debug.Log (_sds);
_green = GameObject.FindWithTag ("Green");
WhenYouDoSomething (_green, out green, out greenScale);
_orange = GameObject.FindWithTag ("Orange");
WhenYouDoSomething (_orange, out orange, out orangeScale);
_purple = GameObject.FindWithTag ("Purple");
WhenYouDoSomething (_purple, out purple, out purpleScale);
_red = GameObject.FindWithTag ("Red");
WhenYouDoSomething (_red, out red, out redScale);
_yellow = GameObject.FindWithTag ("Yellow");
WhenYouDoSomething (_yellow, out yellow, out yellowScale);
}
public Transform FindChild(GameObject parent, string name)
{
if (parent.name == name)
{
Debug.Log("Parent's Name is same as you are searching for");
return null;
}
Transform pTransform = parent.GetComponent<Transform> ();
foreach (Transform t in pTransform)
{
if (t.name == name)
{
return t;
}
}
return null;
}
public void WhenYouDoSomething(GameObject item, out Transform itemTransform, out Vector3 itemScale)
{
if (item == null)
{
Debug.Log ("Item is null");
itemTransform = null;
itemScale = Vector3.zero;
}
else
{
itemTransform = FindChild (item, "line");
itemScale = itemTransform.localScale;
}
}
as you can see When I start the game, and put in the Update Function a Debug.Log of blue, the Log will give me a value. But after I press new Level, the blue value will be null.
Does this mean that it’s not searching for other values after the game is started?
need HELLP!!