C# 围绕unity 2d旋转
我试着绕着另一个物体旋转一个物体。 以下是我正在使用的脚本:C# 围绕unity 2d旋转,c#,unity3d,game-development,C#,Unity3d,Game Development,我试着绕着另一个物体旋转一个物体。 以下是我正在使用的脚本: public GameObject objectToRotate; private bool rotating; private IEnumerator Rotate(Vector3 angles, float duration) { rotating = true; Quaternion startRotation = objectToRotate.transform.rotation; Quaterni
public GameObject objectToRotate;
private bool rotating;
private IEnumerator Rotate(Vector3 angles, float duration)
{
rotating = true;
Quaternion startRotation = objectToRotate.transform.rotation;
Quaternion endRotation = Quaternion.Euler(angles) * startRotation;
for (float t = 0; t < duration; t += Time.deltaTime)
{
objectToRotate.transform.rotation = Quaternion.Lerp(startRotation, endRotation, t / duration);
yield return null;
}
objectToRotate.transform.rotation = endRotation;
rotating = false;
}
public void StartRotation()
{
if (!rotating)
StartCoroutine(Rotate(new Vector3(0, 0, -90), 0.5f));
}
public void LeftToRight()
{
levelinvate.transform.RotateAround(character.transform.position,Vector3.back,90)
我应该编辑什么才能使第一个代码像第二个代码那样旋转(围绕另一个对象,在第一个代码中它只是旋转对象而不是围绕某个对象)?要围绕某个对象旋转,请使用要围绕半径旋转的对象的中心。如果您能告诉我如何实现这一点,我将不胜感激……)使用Start例程(旋转(新矢量3(0,0,-90,0.5f));其中0,0是旋转对象中心的x,y位置,0.5f是旋转半径。看..检查第二个脚本。这就是我想要实现的。我想围绕对象2旋转对象1。但是如何在脚本1中实现这一点?向方法添加参数,以便可以传递对象、位置和位置半径。
public Button rotateLeftToRight, rotateRightToLeft;
public GameObject levelInvarte, character;
}
public void RightToLeft()
{
levelInvarte.transform.RotateAround(character.transform.position, Vector3.back, -90);
}