I'm pretty new to Unity3D and C# so I'm not entirely sure what I'm doing wrong in the following scenario.
In Unity3D I'm attempting to get the value of a variable (target) that is updated when the player moves close enough to the enemy that the script changes target from null to 'enemy' and gets the position and so on and so forth.
The turret that has a script on it for auto-targetting is a child to the main player gameobject.
Whenever I use the following:
targettingScript target;
target = gameObject.GetComponent<targettingScript>();
// or---
target = gameObject.GetComponentInChildren<targettingScript>();
...I can then test with a debug.log that it does pull "null" as it should at start up, but it doesn't seem to update when the turret finds a target and changes target from null.
I've read a few forum posts in various areas that some say you can't do this (pass data from a child component script to another gameobject that is instantiated (IE a missile firing after targetting is completed and then doing a homing-missile style of tracking) and others said that they did a check through all the levels of the gameObject till they found what they wanted, but I'm not understanding what that really means.
My questions are, 1 - is it possible to relay a variable from a child gameobject's component to another instantiated gameobject 2 - if so, how?
I apologize if this is a rather simple concept, but I'm not sure how to troubleshoot it. I'm going to build a new scene and try various gameObjects and child objects and see what I can muster and if I find anything useful I will post it here.
In the mean time, thank you all for your time in reviewing my question.