Unityコードアニメーションを追加し、パラメータを転送
5764 ワード
テストインタフェース
テストコード
コードはとても簡単で、説明することはありません.
注意すべき点は
unity内のアニメーションは、animation controllerによってn個のanimation clipをバインドしますが、ここでは直接生成され、コード実装のanimation clipと見なすことができます
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と見なすことができます