0
我有圖像w /按鈕組件。我正在創建類似庫存的內容,並且我需要將它顯示爲單擊時單擊「紙張」,然後再次單擊時顯示爲「下單」。點擊然後上去,再次點擊,然後下去
這裏是可以自動執行的代碼,我可以手動執行它。請幫忙。
using UnityEngine;
using System.Collections;
public class BMM : MonoBehaviour {
public Vector3 pointB;
IEnumerator Start()
{
var pointA = transform.position;
yield return StartCoroutine(MoveObject(transform, pointA, pointB, 3.0f));
yield return StartCoroutine(MoveObject(transform, pointB, pointA, 3.0f));
}
IEnumerator MoveObject(Transform thisTransform, Vector3 startPos, Vector3 endPos, float time)
{
var i = 0.0f;
var rate = 1.0f/time;
while (i < 1.0f)
{
i += Time.deltaTime * rate;
thisTransform.position = Vector3.Lerp(startPos, endPos, i);
yield return null;
}
}
}
使用這個:http://wiki.unity3d.com/index.php?title=MoveObject –