I have a game in which my main character "dashes" which triples their movement speed and allows them to destroy enemies.
Player Code:
//Starting Dash Coroutine.
if (Input.GetButtonDown("Fire1"))
{
if (timeStamp <= Time.time)
{
StartCoroutine(Dash());
}
}
}
public IEnumerator Dash()
{
isdashing = true;
normalspeed = dashspeed;
yield return new WaitForSeconds(dashtime);
normalspeed = speed;
timeStamp = Time.time + coolDownPeriodInSeconds;
isdashing = false;
}
Enemy Code:
public Movement player;
public void OnCollisionEnter(Collision collision)
{
if (collision.gameObject.tag == "Player" && player.isdashing == true)
{
Destroy(gameObject);
}
}
However, the player does not destroy the enemy. Collision detection works fine, both with other objects AND with the enemy (the player just collides/ bounces off of them. What is the problem with my code?
↧