Question by
HajiyevEl · Jun 25, 2020 at 08:31 PM ·
eventupdate functionaction
Replace Update() with Event or Action? C#
Hi. I want to replace Update() with Event or Action, so that on when subscribed to event it will loop my code like update() function, and stop looping code on unsubscribing. How can it be done? I don't quite understand Events. Code:
private void Update()
{
if (walk && !dead && !attack && distanceBetween > 0.6f)
{
anim.SetFloat("Speed", speed);
transform.position = Vector3.MoveTowards(transform.position, playerTransform, speed * Time.deltaTime);
}
if (speed != 0 && distanceBetween < 0.6f)
{
if (anim.GetFloat("Speed") != 0 )
{
anim.SetFloat("Speed", 0);
if (walk)
{
walk = false;
}
}
}
if (transform.position.x < playerTransform.x && !facingRight && !dead && !attack)
{
Flip(horizontal);
}
else if (transform.position.x > playerTransform.x && facingRight && !dead && !attack)
{
Flip(horizontal);
}
}
Comment
Your answer
