Ok so I have a car which dynamically creates multiple objects inside of it called audio.
From javascript I want to call the object within the object and kill all of them.
So here is what i got
var audioPiece : Object;
audioPiece = GameObject.Find"MyCar/audio");
Destroy(audioPiece);
I’m sure wrong but i am trying!
Use Transform.Find() to get child objects.
GameObject.GetComponentsInChildren would probably be more suitable
_zeta
March 1, 2012, 9:54pm
4
var audioPiece : GameObject;
audioPiece = Transform.Find("MyCar/audio");
Destroy(audioPiece);
Ok must be really confused. I tried this.
var carAudio : Object;
carAudio = Transform.Find(“Cars/MyCar/audio”);
Destroy(carAudio);
here is the error:
Assets/MyScripts/carEnterExit.js(112,40): BCE0020: An instance of type ‘UnityEngine.Transform’ is required to access non static member 'Find
nagata’s code is incorrect. Assuming the script is attached to the parent.
var carAudio = transform.Find("Cars/MyCar/audio");
Destroy(carAudio.gameObject);
think i got it with that one. Thanks much guys!
ok so i lied. it did not work. I think the issue may be the hierarchy.
Cars->MyCar->audio
but the script is attached to a different object under Cars->MyCar->MyTrigger
This is killin me. I should understand this but it has me totally confused.
Then do a GameObject.Find() to get the parent and then Transform.Find() to get the child in that parent.
GameObject cars = GameObject.Find("Cars");
audio = cars.transform.Find("MyCar/audio");
Destroy(audio.gameObject);
But why are you even having to get more audio inside your object?
that was it. now just to loop it to get all of them.
Thanks a ton guys!