public class Move : MonoBehaviour {
public float minX;
public float maxX;
public float speed;
// Use this for initialization
void Start ()
{
}
// Update is called once per frame
void Update ()
{
Vector3 v = new Vector3(transform.position.x + Time.deltaTime * speed, transform.position.y, transform.position.z);
if (v.x > maxX)
{
v.x = minX;
}
if (v.x<minX)
{
v.x = maxX;
}
transform.position = v;
}
}
很简单的逻辑,恍然大悟。