目前,我有一个脚本,它正在发射一个球体,当我按下按钮时,它就会发射;小球出来了,但不会在屏幕上移动,它只是停留在固定的位置。而我希望它在屏幕上向前移动。
脚本:
#pragma strict
public var pellet : Transform;
function Start () {
}
function Update () {
if (Input.GetKeyUp("o"))
{
var pelletfire = Instantiate (pellet, gameObject.Find("pellet_Spawn").transform.position, Quaternion.identity);
pelletfire.rigidbody.AddForce(transform.forward * 500);
}
}谢谢你的建议
发布于 2013-07-01 22:11:29
将您的代码行替换为-
pelletfire.rigidbody.AddForce(transform.forward * 100,ForceMode.Impulse);
有关更多详细信息,请参阅unity中的forcemode文档。
http://unity3d.com/learn/tutorials/modules/beginner/physics/addforce http://docs.unity3d.com/Documentation/ScriptReference/ForceMode.html
您还需要在场景中使用名称为"pellet_Spawn“的GameObject。你的预制件应该有一个刚体附着在它上面。并且脚本需要附加到场景中的GameObject。并从检验员那里设置预制件。
https://stackoverflow.com/questions/17403562
复制相似问题