Hi,when i trigger an object it play a sound,this is my question:
how can i stop other game object sound with triggering this game object?
thankful.
If you want to stop a sound which is playing in another object, you must have some reference to that object - gameObject, transform, collider, rigidbody etc. You can place a Transform variable in your script and assign it in the Inspector:
var otherObject: Transform; // drag the other object here in the Inspector
or you can use GameObject.Find to find it by name:
var otherObject: GameObject = GameObject.Find("NameOfOtherObject");
or get its collider in a trigger or collision event:
var otherObject: Collider;
function OnTriggerEnter(col: Collider){
otherObject = col;
}
function OnCollisionEnter(coll: Collision){
otherObject = coll.collider;
}
Anyway, once you have a reference to the other object, stop the sound with:
otherObject.audio.Stop();
thanks a lot Aldo Naletto for your full answering,
i try it and hopeful to solve it