var script : GameObject
Hi guys, upgrading to unity 5 from 4 broke my game in many places. One of these places is here:
var script : GameObject;
script = gameObject.GetComponentInChildren(BodyParticleScript);
This throws the error "Cannot convert 'BodyParticleScript' to 'UnityEngine.GameObject'."
Are scripts not considered GameObjects anymore? Does anyone know how to fix this?
Answer by LexGear · Oct 13, 2015 at 09:37 AM
This seems to have fixed my issue: http://answers.unity3d.com/questions/343602/best-way-to-reference-child-from-parents-script.html
Answer by Tony_T · Oct 11, 2015 at 09:09 AM
You can use this to access a script var TheScript : ScriptName;
and to call it TheScript.AVarFromTheScript;
Hi Ant0ny, mm that doesn't really answer my question. $$anonymous$$y issue is directly related to the GetComponentInChildren(scriptName) function. I need to be able to access a script IN the children, not attached to the object directly.
var script : GameObject = gameObject.GetComponentInChildren(BodyParticleScript);
And then basically I want to access a function within that child of that script like so:
script.ThisFunction();