gpt4 book ai didi

c# - 如何使用一种方法来旋转多个字符?

转载 作者:太空宇宙 更新时间:2023-11-03 20:52:16 25 4
gpt4 key购买 nike

if (waitinganimation == true)
{
RotateCharacters(animators[2]);
}

if (!endRot)
{
Quaternion goalRotation = Quaternion.Euler(0f, 180f, 0f);
float angleToGoal = Quaternion.Angle(
goalRotation,
animators[0].transform.localRotation);
float angleThisFrame = Mathf.Min(angleToGoal, rotationSpeed * Time.deltaTime);

// use axis of Vector3.down to keep angles positive for ease of use
animators[0].transform.Rotate(Vector3.up, angleThisFrame);
animators[1].transform.Rotate(Vector3.down, angleThisFrame);

// We end if we rotated the remaining amount.
endRot = Mathf.Approximately(angleThisFrame, angleToGoal);
}
{
animators[0].SetBool("Rifle Aiming Idle", true);
animators[1].SetBool("Rifle Aiming Idle", true);
}
}
}

private void RotateCharacters(int[] CharactersIndex)
{
for (int i = 0; i < CharactersIndex.Length; i++)
{
if (!endRotation)
{
Quaternion goalRotation = Quaternion.Euler(0f, -90f, 0f);
float angleToGoal = Quaternion.Angle(
goalRotation,
animators[CharactersIndex[i]].transform.localRotation);
float angleThisFrame = Mathf.Min(angleToGoal, 100 * Time.deltaTime);

animators[CharactersIndex[i]].transform.Rotate(Vector3.down, angleThisFrame);

endRotation = Mathf.Approximately(angleThisFrame, angleToGoal);
}
else
{
animators[CharactersIndex[i]].SetBool("Magic Pack", true);
}
}
}

bool waitinganimation = false;
IEnumerator WaitForAnimation()
{
yield return new WaitForSeconds(3);
waitinganimation = true;
}

首先,我旋转 animators[0][1] 以获得特定的角度目标,然后我旋转 animators[2] 另一个角度目标。相反,我想使用 RotateCharacters 方法进行多次旋转。

如果我调用该方法一次:RotateCharacters(2); 然后例如:RotateCharacters(0,1); 或更好:RotateCharacters (animators[2]);RotateCharacters(animators[0], animators[1]);

所以在更新中我将有两行:

RotateCharacters(animators[2], Quaternion angle);
RotateCharacters(animators[0], animators[1], Quaternion angle);

因此它将同时旋转所有 3 个,但第一个 animators[2] 将旋转到特定角度,然后是另外两个 animators[0]animators[1] 将旋转到另一个角度。

不是它应该看起来的样子,而是想法是进行多次旋转。但是我搞砸了整个方法。

最佳答案

使用 params关键词。 params 集合必须是最后定义的参数,因为它将所有 后续额外参数收集到数组中。基本上,它是从“可选”参数创建数组的简写。

例子:

void RotateAll(Quaternion rotation, params Animator[] anims) {
foreach ( var anim in anims )
ApplyRotation(rotation, anim); // However you want to actually apply the rotation
}

并这样调用它:

RotateAll(new Quaternion(), animators[0], animators[2]); //etc

关于c# - 如何使用一种方法来旋转多个字符?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54121875/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com