The sound of the door does not stop
I use raycast to change the bool Open_Close
if (Input.GetKeyDown("e"))
{
if (Physics.Raycast(transform.position, transform.forward, out hit, DistanceDoor))
{
if(hit.transform.tag == "Door")
{
Debug.Log ("Puerta");
hit.collider.SendMessageUpwards ("OpenDoor", SendMessageOptions.DontRequireReceiver);
}
}
}
This is the script door
using UnityEngine;
using System.Collections;
public class Door : MonoBehaviour {
public Animator anim;
public bool Open_Close;
public AudioSource Audio_Source;
public AudioClip Open;
public AudioClip Close;
void Start ()
{
anim = GetComponent<Animator> ();
Audio_Source = GetComponent<AudioSource> ();
Open_Close = false;
}
void Update ()
{
anim.SetBool ("Open_Close",Open_Close);
if (Open_Close == true)
{
OpenSound ();
}
else
{
CloseSound ();
}
}
void OpenDoor()
{
Open_Close = Open_Close ? false : true;
}
void OpenSound()
{
Audio_Source.clip = Open;
if (!Audio_Source.isPlaying) {
Audio_Source.PlayOneShot (Open);
}
}
void CloseSound()
{
Audio_Source.clip = Close;
if (!Audio_Source.isPlaying) {
Audio_Source.PlayOneShot (Close);
}
}
}
Comment
Your answer
Follow this Question
Related Questions
Parsing error CS8205,Parsing Error CS8205 2 Answers
Sound bug - Emergency HELP 0 Answers
How to Destroy game object horizontally and vertically , when hit by a Raycast 0 Answers
Help with raycast!! 0 Answers