0
我寫了Card類的函數,它應該圍繞它的Y軸旋轉Card。RotateFunction有不同的行爲
public IEnumerator RotateCard(float angle)
{
if(rotating)
yield break;
rotating = true;
float newAngle = curRotation.y + angle;
while(curRotation.y < newAngle)
{
curRotation.y = Mathf.MoveTowards(curRotation.y, newAngle, rotateSpeed * Time.deltaTime);
transform.eulerAngles = curRotation;
yield return null;
}
rotating = false;
}
我不得不在Card.OnMouseDown()這個函數調用:
IEnumerator OnMouseDown()
{
print ("Card clicked");
yield return StartCoroutine(RotateCard(180));
yield return StartCoroutine(gameManager.actionDeck[0].RotateCard(180));
}
其中游戲管理器是包含卡actionDeck的列表對象。
第一次調用是做什麼功能的意圖 - 將卡繞其Y軸旋轉。
另一方面,第二個電話將卡旋轉到一些奇怪的點。
任何想法爲什麼以及如何使其與呼叫#1相同的方式工作?
'yield return null;'...爲什麼? – LightStriker
最有可能圍繞父對象旋轉。也許嘗試'gameManager.actionDeck [0] .gameObject.RotateCard(180)'或類似的東西? –
通過gameObject調用沒有工作 - 它無法訪問RotateCard()函數。產量返回null; ...爲什麼? - 函數必須返回一些東西。這樣它開始工作,所以我沒有問更多的問題... - – user2091377