子弹不动统一
此刻,我有一个正在发射球体的脚本,当我按下使它发射的按钮时;颗粒出来,但不会在屏幕上移动,它只是停留在静止位置.而我希望它在屏幕上向前移动...
At the moment I have a script that is firing a sphere, when i press the button which makes it fire; the pellet comes out but does not move across the screen, it just stays in a stationary position. whereas I would like it to move across the screen forward...
脚本:
#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);
}
}
感谢任何建议
用此替换您的行-
pelletfire.rigidbody.AddForce(transform.forward * 100,ForceMode.Impulse);
pelletfire.rigidbody.AddForce(transform.forward * 100,ForceMode.Impulse);
有关更多详细信息,请参阅unity中的forcemode文档-
For more details look at forcemode documentation in unity-
http://unity3d.com/learn/tutorials/modules/beginner/物理/addforce http://docs.unity3d.com/Documentation/ScriptReference/ForceMode.html
您还需要在场景中使用名称为"pellet_Spawn"的GameObject. 并且您的预制件应附有刚体. 并且脚本需要附加到场景中的GameObject. 并从检查员那里设置预制件.
you also require a GameObject in scene with name "pellet_Spawn". and your prefab should have a rigidbody attached to it. and the script needs to be attached to a GameObject in the scene. and set the prefab from the inspector.