hi all,
i face some problem in my works.
which i intended to slow the player if collide with objects for 5 secs which in the 5 secs, the movement speed will decrease and increase back to the original speed in 5 secs.
just like if the movespeed is 1 and once it collide with the object it turn to 10.6,and in the next seconde, it turns to 10.7, and until 5 sec the speed will increased back to 1.
following is the code i working on:
void OnTriggerEnter(Collider other)//function for obstacles to cause slow on gameobject
{
if ((other.tag == "Obstacle")(trigState==0))
{
slow = (float)(speed * 0.6);
trigState = 1;
StartCoroutine(shake());
Invoke("Delay",1f);
}
void Delay()
{
slow = (float)(speed*0.7);
Invoke("Delay2",1f); //seconds for gameobject to collide another obstacles
}
void Delay2()
{
slow = (float)(speed*0.8);
Invoke("Delay3",1f);
}
void Delay3()
{
slow = (float)(speed*0.9);
Invoke("RepeatDelay",1f);
}
void RepeatDelay()
{
slow = 1;
trigState = 0;//reset
}
public void Update()
{
transform.Translate(Vector3.forward * speed * slow);
}
}
this is the way i am doing, but maybe there is more effecient way to do it.
the main problem i facing is that
if i want to recalculate the slow time if player collide another object in the periods of 5 secs,
how could i make it?
thanks if guides and helps could get from u…thanks =)