【问题标题】:how to do step-by-step code in unity 'void Update{}'?如何在统一'void Update{}'中执行分步代码?
【发布时间】:2019-11-29 19:04:03
【问题描述】:

我要做跟踪器。 这是我团结一致的轨迹 Track image

我想在unity C#脚本方法void Update{}中逐步操作代码1~10, 但我找不到如何制作它。 我使用三角系统、Sin 和 Cos 制作旋转代码。

Rigidbody rigidbody;
public GameObject ball;
Vector3 P1 = new Vector3(-5, 1.5f, 25);
public float theta;

// Start is called before the first frame update
void Start()
{
    rigidbody = GetComponent<Rigidbody>();
}

// Update is called once per frame
void Update()
{
    ball.transform.position = Vector3.MoveTowards(transform.position, P1, 0.05f); // 1st move

    if(theta <210)         // 2nd rotation with trigonometic equations
    {
        theta += 1;
        ball.transform.position = Rot(theta);
    }
}

Vector3 Rot(float theta)   // rotation by trigonometric equations
{

    Vector3 P2;
    P2.x = (3 * Mathf.Cos(theta * Mathf.PI / 180) - 3 * Mathf.Sin(theta * Mathf.PI / 180)) -8;
    P2.y = 1.5f;
    P2.z = (3 * Mathf.Sin(theta * Mathf.PI / 180) + 3 * Mathf.Cos(theta * Mathf.PI / 180)) + 22 ;
    return P2;

}

如果我播放该代码,球就会扭曲到位置 P1 并立即开始旋转 我该如何使用它?

并且不能使用键盘或其他输入处理程序,只能由代码使用

【问题讨论】:

    标签: c# unity3d


    【解决方案1】:

    要统一调试,您需要使用 Visual Studio 调试工具。点击播放按钮“Connect with Unity”,在Unity端播放。您当然需要在需要的地方放置一个调试点。

    注意:您的游戏会在更新调试期间卡住,如果可以并且您需要在游戏视图中看到更新,只需在协程中执行您需要调试的代码即可。 如果您只需要知道变量的值,即使在更新中,您也应该能够毫无问题地对其进行调试。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-12-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多