I am pretty new to Unity and I am doing a project on making a character to move around.
I have successfully move the character around by using Character Controller and manage to open and close the door by pressing the F and G keys respectively.
The problem now I faced is that I can’t seem to put a open and close door sound effect to the door…
I have the following javascripts:
var smooth = 2.0;
var DoorOpenAngle = 90.0;
var DoorCloseAngle = 0.0;
var open : boolean;
var enter : boolean;
var DoorOpen : AudioClip;
var DoorClose : AudioClip;
//Main function
function Update()
{
if(open == true)
{
var target = Quaternion.Euler (0, DoorOpenAngle, 0);
//Dampen towards the target rotation
transform.localRotation = Quaternion.Slerp(transform.localRotation, target, Time.deltaTime * smooth);
}
if(open == false)
{
var target1 = Quaternion.Euler (0, DoorCloseAngle, 0);
//Dampen towards the target rotation
transform.localRotation = Quaternion.Slerp(transform.localRotation, target1, Time.deltaTime * smooth);
}
if(enter == true)
{
if(Input.GetKeyDown("f"))
{
(open) = true;
}
else if(Input.GetKeyDown("g"))
{
(open) = false;
}
}
}
//Activate the Main function when player is near the door
function OnTriggerEnter (other : Collider)
{
if(other.gameObject.tag == "Player")
{
(enter) = true;
}
}
//Deactivate the Main function when player is away from the door
function OnTriggerExit (other : Collider)
{
if(other.gameObject.tag == "Player")
{
(enter) = false;
}
}
var Trigger : AudioClip;
//When player enters the trigger zone
function OnTriggerStay()
{
if(Input.GetKeyDown("f"))
{
if (open) audio.PlayOneShot(DoorOpen);
else audio.PlayOneShot(DoorClose);
}
}
The sound is just not playing or anything…Please do help me… Thank you very much!!