In the Update() of my enemy script, I have it so that the object will Translate up based on speed and time however the first object that is spawned goes beyond the limit I've set at 2.5 while the rest that get spawned work fine. Why is this?
public class EnemyScript : MonoBehaviour
{
int scoreValue = 1;
public int speed = 1;
// Use this for initialization
void Start ()
{
}
private void OnMouseDown()
{
Destroy(gameObject);
}
// Update is called once per frame
void Update ()
{
if(this.transform.position.y <= 2.5f)
{
this.transform.Translate(Vector3.up * speed * Time.deltaTime, Space.World);
}
}
private void OnDestroy()
{
GameManager.IncrementScore(scoreValue);
}
}
↧