I need help with 2d gun script

#pragma strict
var bullet : Rigidbody2D;
var force : float = 1500;
var damage : float = 100;
var reloadtime : float = 4;
var magcount : int = 10;
var magbulletcount : int = 21;
var bulletcount : int = 0;

function Start () {

bulletcount = magbulletcount;

}

function Update () {

if (Input.GetButtonDown(“Fire1”)&& bulletcount > 0){
var instance: Rigidbody2D = Instantiate(bullet, transform.position, transform.rotation) as Rigidbody2D;
var shoot: Rigidbody2D.AddForce(transform.right * force);

}

}

First of all, use script tags correctly please.

Secondly, I’d go and find some tutorials on instantiation. Even though you haven’t described your problem, it’s pretty clear why this script isn’t working. Getting some basic knowledge through tutorials is a great way to prevent frustrations like this!

What help do you need, other than learning how to format your code on the forum?

1 Like