0

目前我有一个脚本正在发射一个球体,当我按下使它发射的按钮时;颗粒出来但不会在屏幕上移动,它只是停留在静止位置。而我希望它在屏幕上向前移动......

脚本:

    #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); 
    }


}

感谢您的任何建议

4

1 回答 1

0

Replace your line with this-

pelletfire.rigidbody.AddForce(transform.forward * 100,ForceMode.Impulse);

For more details look at forcemode documentation in unity-

http://unity3d.com/learn/tutorials/modules/beginner/physics/addforce http://docs.unity3d.com/Documentation/ScriptReference/ForceMode.html

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.

于 2013-07-01T14:11:29.370 回答