Basically, the enemy has two specified points in which it moves until it has reached one point, and then when it reaches the 2nd specified point, it repeats.
Here's the problem though...
![alt text][1]
[1]: /storage/temp/92986-problem.gif
The enemy keeps going past the second point and then it suddenly stops and goes to the right point... which is somehow now moved too.
Here's the code I use for the enemy:
using UnityEngine;
using System.Collections;
public class BMoveAI : MonoBehaviour
{
public float pos1;
public float pos2;
public float speed;
[SerializeField] private bool dirRight;
void Update()
{
if (dirRight)
{
transform.Translate (Vector2.right * speed * Time.deltaTime);
}
else
{
transform.Translate (Vector2.left * speed * Time.deltaTime);
}
if (transform.position.x >= pos1)
{
dirRight = false;
}
else if (transform.position.x <= pos2)
{
dirRight = true;
}
}
}
One other thing: The enemy is parented to another object, so I tried removing the enemy from it, and it still acts in this strange way. Sorry if this question isn't quite clear, I'm not good at explaining myself.
Edit: Sorry about the gif not moving! Don't know what's up with that.
↧