I’m having a problem referencing other gameObjects in my script.
I have some tanks with turrets.
I have parts named, vehicle1, turret, gun, etc.
So I was referencing these parts using Find() as suggested in the docs, but it’s not working.
The problem is that it seems to be finding all similarly parts named across all units, as opposed to just those parts that are children of a specific vehicle.
For example:
Each unit hierarchy is as such: Vehicle > Turret > Gun
So to reference the “Gun” object inside a vehicle that the script resided in:
var turret : GameObject;
var gun : GameObject;
turret = this.gameObject.Find(“Turret”);
gun = turret.gameObject.Find(“Gun”);
My script worked perfectly when there was only one tank. As soon as I added a second, problems started appearing. After much trial and error, I THINK it is because of some kind of referencing conflict.
How do I reference a specific object that is a child of a another specific object?
I would have though that referencing would be something simple like:
Vehicle1.Turret.Gun.
The docs tell me to use Find() in order to reference an object by name, but it seems to be getting the first entity named “Gun” across the whole scene, not just within “Vehicle1”
This can’t be right. But how else am I to reference these objects?