- Home /
How would I play a sound in a certain range of an object?
I am not sure what I have done wrong in this script I have created, I used my knowledge of java to put this together, but not sure why this is not working. taking a guess, maybe I have done it in a wrong layout?
var theplayer : GameObject;
var speed : float;
var range : int;
public var close : AudioClip;
public var aware : AudioClip;
public var retreat : AudioClip;
function Update (){
range=Vector3.Distance(theplay.transform.position,transform.position);
{
if (range<40){
transform.LookAt(theplay.transform.position);
AudioSource.PlayClipAtPoint(aware, transform.position);
}
}
{
range=Vector3.Distance(theplay.transform.position,transform.position);
if (range<20){
AudioSource.PlayClipAtPoint(close, transform.position);
}
}
{
range=Vector3.Distance(theplay.transform.position,transform.position);
if (range<12){
transform.Translate(-Vector3.forward*speed);
AudioSource.PlayClipAtPoint(retreat, transform.position);
}
}
}
Comment
Answer by Filippo94 · Jul 07, 2013 at 11:37 AM
You used "theplay", but the variable's name is theplayer. Why do you use PlayClipAtPoint instead of assign an AudioSource in the inspector and then change the clip?
oh right... I was trying to make it that at different ranges it will make differents sounds
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
I want my trigger sound only to play once! 0 Answers
Sound on collision not working 1 Answer
Play sound on mouse enter 1 Answer
fix sonic like script? 1 Answer