I have written the following script with the intention of having an object moving back and forth on the Y axis. But instead of moving on only the Y, it is moving on a combination of an X and Y. If you could help, that would be great!
using UnityEngine;
using System.Collections;
public class EnemyMovement : MonoBehaviour {
public float min=2f;
public float max=3f;
public float movement=20;
// Use this for initialization
void Start () {
min=transform.position.x;
max=transform.position.x+movement;
}
// Update is called once per frame
void Update () {
transform.position =new Vector3(Mathf.PingPong(Time.time*2,max-min)+min, transform.position.y, transform.position.z);
}
}