Hi. In my script if I hit monster which have this script attached i set him imOnIce bool to true. This working fine. When imOnIce is true i change monster speed to 0 and after this start coroutine which change speed again after 5 seconds. Problem is when i try hit monster again after first and whene old freeze still working. I wont to stop old coroutine and start all think from begin. So when i hit monster i check that monster have imOnIce true and if it is i stopCoroutine. Unfortunately even my script is enter in stopCoroutine it dosent work and my last coroutine end after 1/2 seconds. What
s wrong?
void OnTriggerEnter2D (Collider2D collider) {
ShotScript shot = collider.gameObject.GetComponent<ShotScript> ();
if (shot != null)
{
if (shot.isHit != isEnemy)
{
PlayerData.hittedEnemys++;
EffectOn(PlayerActiveSkills.actualActiveSkill);
HP -= shot.damage;
enemyHpBar.value = HP;
if(imOnIce) {
speed = new Vector2(0,0);
StartCoroutine("ChangeSpeedAfterTime", 5);
}
}
}
}
void EffectOn( SkillType effectType ) {
if(effectType == SkillType.IceArrow) {
if(imOnIce) {
Debug.Log("IM IN");
StopCoroutine("ChangeSpeedAfterTime");
}
imOnIce = true;
}
}