- Home /
Problems making an audio JumpScare
Ok guys, I'm going to cut to the chase. I've been skewering these forums for days now trying to get the right skript for a perfect audio jumpscare (WHERE THE TRIGGER IS DELETED AFTERWARD, SO THAT IT CAN ONLY HAPPEN ONCE) and it seems like no matter what I try to fix or copy and paste, it will not work! I want to make it to where the player walks through a BoxCollider named "TreeSnapTrigger" and an audio clip that I have attached to the collider plays. And I only want it to be able to play ONE TIME. This is my script. Please tell me what i'm doing wrong.
var ThisTrigger : GameObject;
function OnTriggerEnter(other: object) {
if (otherObj.tag == "Player")
{
audio.PlayOneShot();
}
else {
audio.Stop();
}
}
function OnTriggerExit(other: object) { Destroy (ThisTrigger);
}
Answer by bubzy · Jun 16, 2013 at 09:05 PM
if (otherObj.tag == "Player")
{
audio.PlayOneShot();
Destroy(gameObject)
}
don't know why so many people use "`this`" its generally implied I think (i've never used it yet)
Ok, so I did what you said, and this is my new script
var ThisTrigger : GameObject;
function OnTriggerEnter(other: object) {
if (otherObj.tag == "Player")
{ audio.PlayOneShot(); Destroy(gameObject); } }
BUT NOW, its giving me this error- Assets/TreeSnapTrigger.js(3,32): BCE0018: The name 'object' does not denote a valid type ('not found'). Did you mean 'UnityEditorInternal.Object$$anonymous$$emoryInfo'?
// Destroy everything that enters the trigger
function OnTriggerEnter (other : Collider)
{
if (other.tag == "Player");
{
audio.PlayOneShot();
Destroy(gameObject);
}
}
disclaimer : I don't know JS, this is from
http://docs.unity3d.com/Documentation/ScriptReference/Collider.OnTriggerEnter.html
from the look of it though, and without being a jerk, I think that you need to brush up a bit on your program$$anonymous$$g skills, starting straight out with a scripting language isn't always the best.
Answer by sgPwnZone · Jun 17, 2013 at 08:21 AM
Ok, I figured it out. FOR ANYONE THAT COMES ACROSS THIS FORUM, THIS IS THE CODE YOU USE FOR AN AUDIO JUMPSCARE.
pragma strict
var Sound:AudioClip; var thisobject:GameObject;
function OnTriggerEnter (o:Collider) { audio.PlayOneShot (Sound) ;
}
function OnTriggerExit (o:Collider) { Destroy(gameObject); }
Your answer
Follow this Question
Related Questions
Getting audio.PlayOneShot to work 2 Answers
On trigger enter play sound problem 2 Answers
Problems with navmeshagent with trigger 1 Answer
trigger audio and text from array 0 Answers
Play Audio on Key Press when within trigger or use raycast?? 2 Answers