Question by
StAngel1 · Nov 27, 2017 at 12:37 AM ·
speedienumeratoryield waitforseconds
2D platformer IEnumerator problems
I want my hero to be slowed down for 2 seconds by enemy bullet.
public float speed = 3f;
And on collision with the bullet I call:
private void OnCollisionEnter2D(Collision2D collision)
{
if (collision.gameObject.tag == "AnorexBullet")
{
speed = 1f;
Debug.Log("Hit");
StartCoroutine(SpeedDisabler());
speed = 3f;
}
}
IEnumerator SpeedDisabler()
{
yield return new WaitForSeconds(3);
}
The problem I have that the speed won't change... What am I missing?
Comment
Answer by xofear · Dec 13, 2018 at 05:45 AM
@StAngel1 try this.
private void OnCollisionEnter2D(Collision2D collision)
{
if (collision.gameObject.tag == "AnorexBullet")
{
Debug.Log("Hit");
StartCoroutine(SpeedDisabler()); }
}
IEnumerator SpeedDisabler()
{
speed = 1f;
yield return new WaitForSeconds(3);
speed = 3f;
}
Your answer
Follow this Question
Related Questions
Could not load source 'Coroutines.cs': No source available. 1 Answer
Why isn't WaitForSeconds working? 1 Answer
i need a help with script Animation Trigger 1 Answer
LookRotation with constant speed 0 Answers
C# FPS Speed Boost 0 Answers