我想知道如果有一種方式來增加(對我來說),120度每次我推「按鈕a」,再減去120度的的Z軸旋轉每次我推「ButtonB」, 2D精靈(預製)。統一 - 如何從一個角度添加或減去選定的度數?
這是我使用的是此刻的代碼,但它只能旋轉一次左,右後:提前
function TouchOnScreen()
{
if (Input.touchCount > 0)
{
var touch = Input.touches[0];
if (touch.position.x < Screen.width/2)
{
var RSpeed = 10.0f
transform.rotation = Quaternion.Lerp (transform.rotation,Quaternion.Euler(0,0,120), Time.deltaTime*RSpeed);
Debug.Log("RotateRight");
}
else if (touch.position.x > Screen.width/2)
{
var LSpeed = 10.0f
transform.rotation = Quaternion.Lerp (transform.rotation,Quaternion.Euler(0,0,-120), Time.deltaTime*LSpeed);
Debug.Log("RotateLeft");
}
}
}
謝謝!
注意:如果可以,請使用unityscript,我對編碼相當陌生,unityscript是目前爲止我所知道的。從online documentation它表明該函數的簽名是
static function Lerp(from: Quaternion, to: Quaternion, t: float): Quaternion;
,這意味着第二個參數
感謝您的回答@workoverflow,但我得到這個錯誤:BCE0051:運算符'+'不能用於'UnityEngine.Quaternion'類型的左側和右側類型'UnityEngine.Quaternion'。 – Bartvb98 2014-09-11 13:44:53