Ah, overlooked something myself. StartIsActive is never going to be true. If I’m holding down keypad0, you’re constantly setting it back to false. Even if I enter the trigger which sets it to true, it will be set back to false in update pretty much right away since I’m holding down keypad0.
I’m still not sure what you are trying to do 100%. Your code is very confusing, but I tried to modify it for you. I commented out a bunch of stuff because I wasn’t sure what was going on or should happen.
This is untested, say it might not be perfect, and in some cases I feel this could be done a lot better.
using UnityEngine;
using System.Collections;
//[RequireComponent(typeof(AudioSource))]
public class NavigationMove : MonoBehaviour
{
[SerializeField]
AudioSource m_start, m_correct, m_wrong;
[SerializeField]
GameObject m_GameRule, m_GameOver1, m_GameOver2, m_GameOver3, m_PressKeyNote, m_WrongButton, m_StartGame, m_Question1, m_CorrectNote, m_WrongNote1, m_Question2, m_TurnLeftNote, m_WrongNote2,
m_ReplayNote, m_Question3, m_Question4, m_EndFirstStage, m_HospitalArrive, m_SecondStageQuestion, m_Question5, m_Question6, m_Question7, m_TurnRightNote, m_ScoreNote, m_GameOver4;
NavMeshAgent agent;
GameObject m_hospital;
Rigidbody m_Rigidbody;
// Use this for initialization
void Start()
{
agent = GetComponent<NavMeshAgent>();
m_hospital = GameObject.FindWithTag("Hospital");
m_Rigidbody = GetComponent<Rigidbody>();
m_start = GetComponent<AudioSource>();
m_start.Play();
}
bool startisActive = false;//means m_StartGame.SetActive(false);
bool rulesAreActive = false;
// Update is called once per frame
void Update()
{
agent.destination = m_hospital.transform.position;
if (Input.GetKey(KeyCode.Keypad0) && !startisActive) //This will move you forward till you hit the trigger. Requires holding down the key.
{
m_GameRule.SetActive(false);
m_start.Play();
agent.destination = m_hospital.transform.position;
agent.speed = 20;
}
if(rulesAreActive) //After trigger rules, this checks if you hit any key other than 0 and then checks the time.
{
if (Input.GetKeyDown(KeyCode.Keypad1) || Input.GetKeyDown(KeyCode.Keypad2) || Input.GetKeyDown(KeyCode.Keypad3) ||
Input.GetKeyDown(KeyCode.Keypad4) || Input.GetKeyDown(KeyCode.Keypad5) || Input.GetKeyDown(KeyCode.Keypad6) ||
Input.GetKeyDown(KeyCode.Keypad7) || Input.GetKeyDown(KeyCode.Keypad8) || Input.GetKeyDown(KeyCode.Keypad9))
{
if (Time.time > 15f)
{
m_StartGame.SetActive(false);
m_GameOver2.SetActive(true);
}
}
}
if (startisActive) //You've now activated the redlightcollider trigger and will no longer move forward.
{
if ((Input.GetKeyDown(KeyCode.Keypad1))) //Player hits 1
{
m_StartGame.SetActive(false);
m_Question1.SetActive(true);
}
else if (Input.GetKeyDown(KeyCode.Keypad0) || Input.GetKeyDown(KeyCode.Keypad2) || Input.GetKeyDown(KeyCode.Keypad3) ||
Input.GetKeyDown(KeyCode.Keypad4) || Input.GetKeyDown(KeyCode.Keypad5) || Input.GetKeyDown(KeyCode.Keypad6) ||
Input.GetKeyDown(KeyCode.Keypad7) || Input.GetKeyDown(KeyCode.Keypad8) || Input.GetKeyDown(KeyCode.Keypad9)) //Player hits another key than 1
{
//**********Something should happen here? Not sure if game is suppose to be over again or what happens?
//if (Input.GetKey(KeyCode.Keypad1))
//{
// m_StartGame.SetActive(false);
// m_Question1.SetActive(true);
//}
//else if (Time.time > 15f)
//{
// m_StartGame.SetActive(false);
// m_GameOver2.SetActive(true);
//}
}
}
//*********Not sure what this is suppose to do...
//else if (Input.GetKey(KeyCode.Keypad1) || Input.GetKey(KeyCode.Keypad2) || Input.GetKey(KeyCode.Keypad3) ||
// Input.GetKey(KeyCode.Keypad4) || Input.GetKey(KeyCode.Keypad5) || Input.GetKey(KeyCode.Keypad6) ||
// Input.GetKey(KeyCode.Keypad7) || Input.GetKey(KeyCode.Keypad8) || Input.GetKey(KeyCode.Keypad9))
//{
// if (Input.GetKey(KeyCode.Keypad0))
// {
// m_start.Play();
// agent.destination = m_hospital.transform.position;
// agent.speed = 20;
// }
// else if (Time.time > 15f)
// {
// m_GameRule.SetActive(false);
// m_GameOver1.SetActive(true);
// }
//}
}
void OnTriggerEnter(Collider other)
{
if (other.gameObject.layer == LayerMask.NameToLayer("Collider"))
{
m_start.Pause();
agent.speed = 0;
}
if (other.tag == "RuleCollider")
{
m_GameRule.SetActive(true);
rulesAreActive = true;
}
if (other.tag == "RedLightCollider")
{
m_GameRule.SetActive(false);
m_StartGame.SetActive(true);
startisActive = true;
rulesAreActive = false;
}
}
}