Question by
LordOfKspModding · Feb 08, 2019 at 11:35 PM ·
c#collisioncollision detectioncollisiondetectionenemy health
Player cannot destroy enemy
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?
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220612191407im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Lose Health when GameObject enters collider? (OnTriggerEnter) 2 Answers
Cube wont destroy on collision 0 Answers
[SOLVED]OverlapingSphere damage only one enemy 1 Answer
Collision With Text 0 Answers