using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; public class LRMove1 : MonoBehaviour { public float fSpeed = 1.0f; public int iDir = 1; public float fX=0.0f; public int iMargin = 10; public Text txtSpeed; public Text txtMargin; // Use this for initialization void Start () { txtSpeed.text = "Speed:" + string.Format("{0:F1}",fSpeed); txtMargin.text = "Margin:" + iMargin.ToString (); } // Update is called once per frame void Update () { if (iDir > 0) { if (fX < iMargin) { fX = fX + fSpeed*Time.deltaTime; this.transform.position = new Vector3 (fX, 0, 0); } else { iDir = -1; } } else { if (fX > (iDir*iMargin)) { fX = fX + (fSpeed*Time.deltaTime*iDir); this.transform.position = new Vector3 (fX, 0, 0); } else { iDir = 1; } } } }