c# - 如何使用 Unity 的 Update 函数指定对象的旋转值
问题描述
我想在 Unity 中指定对象旋转值。
我不想旋转对象。
我写了以下代码。
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class test_rotate : MonoBehaviour {
int test_x = 10;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
this.transform.Rotate(test_x, 0, 0);
}
}
然后对象开始旋转。
这不是我想要的。
我只想将对象的旋转值设置为(10,0,0)。
我还尝试了以下代码:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class test_rotate : MonoBehaviour {
int test_x = 10;
// Use this for initialization
void Start () {
this.transform.Rotate(test_x, 0, 0);
}
// Update is called once per frame
void Update () {
}
}
然后它按预期工作,但我想用 Update 函数而不是 Start 函数来做到这一点。
我该怎么办?
解决方案
transform.Rotate()
每次调用时都会旋转对象。
你想要做的是设置变换的旋转:transform.rotation = Quaternion.Euler(test_x, 0, 0);
推荐阅读
- c++ - 基于模板类型的类类型
- php - 这是什么意思 < die("连接失败:" . $conn->connect_error); >
- javascript - React.Component 以外的继承组件类抛出“超级表达式必须为空或函数”异常
- ios - 推送通知点击获取 url 并在 View Controller , iOS , Swift4.2 中显示
- javascript - 如何阻止 css translate 将元素带到前面?
- mysql - MySQL 多个唯一列
- jquery - Wordpress AJAX 调用返回未定义
- python - 递归上传目录(其中包含目录)到 FTP
- ionic-framework - 在生产构建离子3中没有获得本地通知声音
- javascript - 修复javascript中的变量增量