[ad_1]
I’ve created Dino object, which is the enemy within the recreation and it must be on the a number of positions within the recreation (3 or 4). So I’ve created a script for it and I need one thing like that:
When participant is near it, it ought to change it is velocity, course perhaps, and the animation.
The downside is, when participant is near the primary Dino the modifications are made on all of the Dinos within the Scene. So how can I repair that? Here is my Dino operate:
void DinoMotion()
{
playerPos = GameObject.Find("Player").remodel.place.x;
//wallPos = GameObject.FindGameObjectWithTag("Wall").remodel.place.x;
dinoPos = remodel.place.x;
//transfer Dino
tempPos = remodel.place;
tempPos.x += velocity * Time.deltaTime;
remodel.place = tempPos;
//Dino Follows Player
int pictw = WallDestroy.PlayerIsCloseToWall;
if (pictw == 1)
{
if (playerPos < dinoPos - 2)
{
velocity = -2f;
sr.flipX = true;
animator.SetBool("DinoRunParam", true);
}
else if (playerPos > dinoPos + 2)
{
velocity = 2f;
sr.flipX = false;
animator.SetBool("DinoRunParam", true);
}
}
}
[ad_2]