Question by
ashisunoriginal · Feb 22, 2018 at 03:44 AM ·
scripting beginnerdoorsound effects
Adding Sound to an Existing Door Open Script
Hello, I am using a script that came with the Sci-Fi Styled Modular Pack in the Unity asset store which opens doors that come with the pack. I want to add sound when the door opens. I have been trying different ways of adding it to the script but none of them have worked so far. Any ideas?
Here is the existing code:
#pragma strict
private var anim : Animator;
var character : GameObject;
var distanceToOpen:float = 5;
public var characterNearbyHash : int = Animator.StringToHash("character_nearby");
function Start () {
anim = GetComponent("Animator");
}
function Update () {
var distance = Vector3.Distance(transform.position,character.transform.position);
if (distanceToOpen>=distance){
anim.SetBool(characterNearbyHash, true);
}else{
anim.SetBool(characterNearbyHash, false);
}
}
Comment
Your answer
Follow this Question
Related Questions
How do I get an audio clip to play at a specific time? 0 Answers
In a scene with multiple doors if one is opened lock all of others? 1 Answer
AudioSource dissappears in variable window on Play 2 Answers
Error CS0122: inaccessable due to protection level 1 Answer
Is it better to split a script into different scripts? 1 Answer