Timer onTriggerEnter doesn't launch
Hi !
In my project, I am trying to set on a powerup (just modify speed) during 15sec on my player when this one is colliding with a specific object.
My problem : I put a boolean to true in order to launch my stuff in the Update() function, but I can't acess to my stuff. So I put a Debug.Log to check, and it never appears. I don't understand why.
Thank you for your help !
private bool runTimer = false;
private float timeTimerLeft;
private bool death;
private float elapsedTime;
private void Start()
{
timeTimerLeft = 15.0f;
}
private void Update()
{
if (runTimer)
{
death = Manager.Instance.GetDeath();
elapsedTime = Time.deltaTime;
while (elapsedTime < 5.0f && !death)
{
PlayerMovements.Instance.SetSpeed(4.0f);
if (death)
{
Instantiate(gameObject);
}
}
PlayerMovements.Instance.SetSpeed(8.0f);
runTimer = false;
}
}
private void OnTriggerEnter(Collider other)
{
if (other.CompareTag("Player"))
{
runTimer = true;
Destroy(gameObject);
death = Manager.Instance.GetDeath();
}
}
Comment
did you try to set your functions public? That is probably the problem.
Your answer
Follow this Question
Related Questions
ANIMATION TRIGGER DOESN'T PLAY 1 Answer
I can't figure out why a game object isn't being destroyed. 0 Answers
My AI Script doesn't make my AI turn. 1 Answer
Get list of enemies in range 1 Answer
Problems with using OnTriggerStay2d 0 Answers