Hello,
I just added a new gun in my fps game and I attached the same script to my new gun as to my previous weapons which work fine. I obviously changed the variables so that they fit my new gun, but all the code is the same:
var projectilePrefab : Transform;
var force : float = 20000;
static var mg36clipSize : int = 100;
var mg36fullClip : int = 100;
var projectile;
var font : Font;
var scopeCam : Camera;
function Awake (){
mg36clipSize = mg36fullClip;
}
function Update () {
scopeCam.gameObject.active = false;
if (Input.GetButton("Fire1") && mg36clipSize > 0){
mg36clipSize--;
projectile = Instantiate (projectilePrefab,
GameObject.Find("mg36_spawnPoint").transform.position,
GameObject.Find ("First Person Controller").transform.rotation);
projectile.rigidbody.AddForce (projectile.transform.right * force);
wait();
}
}
function OnGUI (){
GUI.skin.font = font;
GUI.contentColor = Color.red;
GUI.Label (Rect (10,600,100,100), "" + mg36clipSize);
}
function wait (){
yield WaitForSeconds (0.2);
}
However, on this gun, when I shoot the projectile goes off to the side for some reason. Does anyone know how this can be fixed?
Thanks a lot, its probably just a really stupid problem but I’m a noob