【问题标题】:Cant get Vector3.right to work with transform.Rotate in unity无法让 Vector3.right 与 transform.Rotate 一起工作
【发布时间】:2019-07-20 08:33:12
【问题描述】:

我试图让我的相机围绕它分配到的游戏对象旋转。到目前为止,我可以让它围绕游戏对象旋转,但它是向左而不是向右旋转。任何帮助表示赞赏。这是我的代码。

using UnityEngine;
using System.Collections;
using UnityEngine.SceneManagement;

public class CameraRotate : MonoBehaviour
{
public float speed;
float time = 5.0f;
public bool updateOn = true;

void Start()
{
    StartCoroutine(updateOff());
}

void Update()
{
    if (updateOn == true)
    {
        if (time >= 0)
        {
            time -= Time.deltaTime;
            return;
        }
        else
        {
            transform.Rotate(0, speed * Time.deltaTime, 0);
        }
    }
}
IEnumerator updateOff()
{
    yield return new WaitForSeconds(10.0f);
    updateOn = false;
}
}

【问题讨论】:

  • 你的意思是你想让物体逆时针转动而不是顺时针转动?你为什么不直接打电话给transform.Rotate(0, -speed * Time.deltaTime, 0);
  • 啊。我是 C# 新手。我试图做 transform.Rotate(-0, speed * Time.deltaTime, 0);
  • 好吧-0 = 0 ;)
  • 是的。太感谢了。现在我的介绍动画完成了。

标签: c# unity3d vector rotation


【解决方案1】:
using UnityEngine;
using System.Collections;

public class CameraRotate : MonoBehaviour
{
    public float speed;
    float time = 5.0f;
    public bool updateOn = true;

void Start()
{
    StartCoroutine(updateOff());
}

void Update()
{
    if (updateOn == true)
    {
        if (time >= 0)
        {
            time -= Time.deltaTime;
            return;
        }
        else
        {
            transform.Rotate(0, -speed * Time.deltaTime, 0);
        }
    }
}
    IEnumerator updateOff()
    {
        yield return new WaitForSeconds(10.0f);
        updateOn = false;
    }
}

【讨论】:

    猜你喜欢
    • 2012-10-02
    • 1970-01-01
    • 2020-02-29
    • 2011-04-25
    • 2014-11-22
    • 2014-05-15
    • 2010-10-16
    • 2019-11-27
    • 2017-02-12
    相关资源
    最近更新 更多