測試界面
button一個
sprite一個
測試代碼
public class BgObject : MonoBehaviour { void Start() { List<string> btnsName = new List<string>(); btnsName.Add("login"); foreach (string btnName in btnsName) { GameObject btnObj = GameObject.Find(btnName); Button btn = btnObj.GetComponent<Button>(); btn.onClick.AddListener(delegate() { this.OnClick(btnObj); }); } } public void OnClick(GameObject sender) { switch (sender.name) { case "login": Dictionary<string,string> dic = new Dictionary<string,string>(); dic.Add("111","333"); StartCoroutine(flip(dic)); break; default: Debug.Log("none"); break; } } IEnumerator flip(Dictionary<string, string> dic) { Text infoText = (Text)GameObject.Find("info").GetComponent<Text>(); infoText.text = dic["111"]; Transform obj = GameObject.Find("dizhu").transform; bool isDone = false; while (!isDone) { float x = obj.localPosition.x + Time.deltaTime; obj.localPosition = new Vector3(x, 0,0); if (obj.localPosition.x >= 0) { isDone = true; } yield return new WaitForSeconds(1 / 60); } } // Update is called once per frame void Update () { }
代碼非常簡單,沒有什么好說明的
需要注意的一點就是
unity里面的動畫,由animation controller去綁定n個animation clip,但是在這里是直接生成的,可以當成是代碼實現的animation clip