Ran into another problem today. So, to start with, I had a huge custom editor script, cluttered, looked messy, not easy to understand. So I went to try a different approach. I have an enum which basically states what type of horror event this object is. Door rotation, audio play, etc. On my object, I have two scripts of the same type (horrortrigger) with one being set to Audio in the enum, and the other set to door rotation. Problem is, only one of them triggers and the other is totally ignored.
This piece of code is inside the Raycast check, to determine if the object being looked at has a HorrorTrigger component.
So, essentially, how do i get two components of the same type to run but before different actions? Is there a way? Or should I carry on trying to write a really long editor?
P.S. The b_activated boolean variable is to stop functions from running constantly (because the calls are being made inside of the update function)
It was going so well…till the audio clips decided to stop running correctly…
Basically, one clip after the other should play. But, they do not. You know what’s strange? If i attach two horror event scripts to my door, and make them both of type ‘Audio’ I get no problems at all. Yet, when one horror trigger is ‘Audio’ and the other ‘Door open’ it messes up. Please ignore the comments, I’ve not got round to changing them xD My code is posted below…these are the functions I am calling. Again, if one object has two horror scripts and BOTH are set to type ‘Audio’ no problems. Yet, one object, two horror scripts, one of type Audio and the other Door Open, the Audio horror type works fine but the Door Open refuses to play at all. The if statement in ‘CreakOpenDoor’ does return true. So unity says its playing…but its not.
/*
*
* Summary: OnTriggerEnter is called to determine if the player has entered a Box Collider that is setup within the scene.
* This handles some of, if not the majority of the 'Jump Scare' events. Once the player has entered the OnTriggerEnter()
* it is imperitive that is destroyed afterwards to prevent the same event happening twice.
*
* Parameters: Collider other - The object that the horror trigger collides with to perform a certain action
*
* */
public IEnumerator CallAudioHorrorEvent()
{
yield return new WaitForSeconds(m_playMusicDelay);
// If this horror event requires a loop, Invoke the method.
if (m_requireAudioLoop) {
// Call an invoke repeating, and only repeat when the clip has finished playing
InvokeRepeating("RequiredLoop", 0, m_audioClip.length);
Debug.Log("Message from HorrorTrigger on Gameobject " + this.gameObject.name + ": Repeating audio called");
} else {
// However, if we do not need a looped audio clip, simply play the audio once
audioSource.PlayOneShot(m_audioClip);
// Call the method to destroy the audio clip after it has finished playing
StartCoroutine(DestroyAudioClip(m_audioClip.length));
}
}
public IEnumerator CreekOpenDoor()
{
yield return new WaitForSeconds(m_doorOpenDelay);
Debug.Log("Calling CreakDoor Open");
beginDoorRotation = true;
audioSource.clip = m_doorCreakAudio;
audioSource.Play();
if(audioSource.isPlaying && audioSource.clip.name == m_doorCreakAudio.name)
{
Debug.Break();
}
Debug.Log(m_doorCreakAudio.loadState);
}