如何通过代码倒置GameObject?
在Unity中,火箭上升后着陆。但是,它着陆时是图中这个样子的:
我想让它倒过来着陆,怎样通过代码来实现?
目前的代码是:
double t = 5.0;void Update () {
GameObject Paraquedas;
GameObject CorpoNariz;
CorpoNariz = GameObject.Find("Corpo_Nariz");
Paraquedas = GameObject.Find("Paraquedas");
rigidbody.AddForce(transform.up * 15);
t -= Time.deltaTime;
if (t <= 0) {
Destroy (CorpoNariz);
Paraquedas.renderer.enabled = true;
transform.Rotate(Time.deltaTime, 0, 0);
rigidbody.AddForce(-transform.up * 50);
rigidbody.drag = 5;
}
}
}
原问题:How to make a GameObject upside down through code?
回答:
回答:
David
只要把Y轴从1改成-1就可以了:
gameObject.transform.localScale = new Vector3(1,-1,1);
Loser:
这是Unity旋转的脚本参考文档: http://docs.unity3d.com/Documentation/ScriptReference/Transform.Rotate.html
试试版本3的旋转功能。看一下下面的例子:
"void Rotate(Vector3 axis, float angle, Space relativeTo = Space.Self);"
using UnityEngine;using System.Collections;
public class Example : MonoBehaviour {
void Update() {
transform.Rotate(Vector3.right, Time.deltaTime);
transform.Rotate(Vector3.up, Time.deltaTime, Space.World);
}
}
以上是 如何通过代码倒置GameObject? 的全部内容, 来源链接: utcz.com/p/189416.html