Need help fixing syntax errors

var Char_Bullet : Transform;

function Update ()
{
    if(Input.GetButtonDown("Fire1"))
    {
        var bullet -  Instantiate(Char_Bullet,GameObject.Find("Gun_Spawn").transform.position,Quaternion.identity);
        bullet.rigidbody_Addforce(transform.forward * 2000);

    }
}

hey, im new to unity but i got the code from a video, trying to show me how to make my gun shoot.

i always get the error Assets/Standard Assets/Scripts/Shoot_Rigid_Bodys.js(6,35): UCE0001: ';' expected. Insert a semicolon at the end.

Help?

1 Answer

1

there are a few errors there

you're using - instead of = after bullet, you don't have a ) after Quaternion.identity, and you're using _ instead of . for rigidbody.AddForce

Corrected:

var Char_Bullet : Transform;

function Update ()
{
    if(Input.GetButtonDown("Fire1"))
    {
        var bullet  = Instantiate(Char_Bullet,GameObject.Find("Gun_Spawn").transform.position,Quaternion.identity);
        bullet.rigidbody.AddForce(transform.forward * 2000);
    }
}

when i fire it just falls out, and i get error MissingMethodException: Method not found: 'UnityEngine.Rigidbody.Addforce'.

Mike - change Addforce to AddForce (capital F)

Ugh, slaps his keyboard. Fixed, thanks