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; //1:Right -1:left public float fX=0.0f; public float fY=0.0f; public int iMargin = 9; public Text txtSpeed; public Text txtMargin; // Use this for initialization void Start () { } // Update is called once per frame void Update () { txtSpeed.text = string.Format("{0:F0}",fSpeed); txtMargin.text = iMargin.ToString(); if (iDir > 0) { if (fX < iMargin) { fX = fX + fSpeed * Time.deltaTime; //fY = fY + fSpeed * Time.deltaTime; //fX = fX + fSpeed; this.transform.position = new Vector3 (fX, fY, 0); } else { iDir = -1; } } else { if (fX > (iDir*iMargin)) { fX = fX + (fSpeed*Time.deltaTime*iDir); this.transform.position = new Vector3 (fX, fY, 0); } else { iDir = 1; } } } public void SS() { if(fSpeed>0) fSpeed = fSpeed - 1.0f; } public void SA() { if(fSpeed<10) fSpeed = fSpeed + 1.0f; } public void MS() { if(iMargin>1) iMargin = iMargin - 1; } public void MA() { if(iMargin<8) iMargin = iMargin + 1; } }