- Home /
Play Animation and Sound when enter collider
Hey guys, I've a problem. I have the following script added to a collider but when the player enters the collider nothing happens..'
I tried the two following scripts:
//SCRIPT ONE
#pragma strict
var playerInArea : boolean = false;
var jumpscare01fx : AudioClip;
function OnTriggerEnter() {
playerInArea = true;
}
function OnTriggerExit() {
playerInArea = false;
}
if(playerInArea == true) {
animation.Play("jumpscare01");
PlaySound();
}
function PlaySound(){
audio.clip = jumpscare01fx;
audio.Play();
}
//SCRIPT 2
#pragma strict
var playerInArea : boolean = false;
var jumpscare01fx : AudioClip;
function OnTriggerEnter() {
playerInArea = true;
}
function OnTriggerExit() {
playerInArea = false;
}
if(playerInArea == true) {
animation.Play("jumpscare01");
audio.Play("jumpscare01fx");
}
Script one simply just doesn't do anything and script 2 gives the following error: BCE0023: No appropriate version of 'UnityEngine.AudioSource.Play' for the argument list '(String)' was found.
The playerInArea does become true when I enter the collider. So the only problem is that audio and anim. isn't playing.
Answer by DaveA · Sep 04, 2013 at 06:23 PM
I found something but still isn't working.. Thanks anyways. (Btw: I already searched google before asking, just bad search terms.)
Your answer
Follow this Question
Related Questions
Selecting Object From Top Causes NullReference 1 Answer
Script error: OnTriggerEnter 1 Answer
The name 'Joystick' does not denote a valid type ('not found') 2 Answers
Dying Script error 2 Answers
Can you make this work? (Click Collider = Make Sound) 2 Answers