Hello, total noob here - I suspect the following problem is me failing to understand how Unity “does things”.
So, I’m building a Tower Defence game and I want to spawn a wave of creeps. In my object hierarchy I’ve built an “Ant” with a mesh underneath it. Attached to Ant is the CharacterMotor and AntThink, its simple AI.
I have a separate item in the hierarchy called “AntSpawner”. Its job is just to spawn Ants at its current location.
I can instantiate the Ants no trouble like so:
void Start () {
ant = GameObject.FindGameObjectWithTag("ant");
antt = ant.transform;
}
void Update () {
if (Time.fixedTime < nextspawn)
return;
nextspawn = Time.fixedTime + 2;
Transform clone = Instantiate(antt, this.transform.position, this.transform.rotation) as Transform;
However, this only gives me the ant as a Transform – what I actually want to do is now tweak the properties of the ant as specified in the AntThink class. Unity won’t allow me to simply cast to AntThink on the last line of my example.
What should I do? What am I doing wrong?
Thanks!