mixZone
1
How do i add delay before moving my object towards player
This is my code
void MoveInCircle()
{
stopped = false;
following = true;
transform.position = Vector2.MoveTowards(this.transform.position, player.transform.position, speed * Time.deltaTime);
}
If player has moved, this method should only start after some delay
First Method: Simply add a Coroutine that will call your function after some delay and call the Coroutine instead of the function.
Second Method: Add a timer variable that will count up every update and when it reaches a certain value, call your function.
mixZone
3
How do i make this timer in this script?
private void Update()
{
player = GameObject.FindGameObjectWithTag("Player");
if (player != null)
{
distance = Vector2.Distance(transform.position, player.transform.position) * 100;
if (distance <= 550 && attacked == true)
{
timer2 = 0;
can_shoot = true;
follow();
timer += Time.deltaTime;
if (timer > 2 && can_shoot == true && player != null && following == true)
{
timer = 0;
shoot();
if (attacked == false)
{
Patrol();
}
}
}
}
}
public bool follow()
{
if (distance <= 550 && player != null && distance > 300)
{
Follow2();
return true;
}
else
{
return false;
}
}
void Follow2()
{
timer5 = 1;
timer5 -= Time.deltaTime;
stopped = false;
following = true;
transform.position = Vector2.MoveTowards(this.transform.position, player.transform.position, speed * Time.deltaTime);
}