Quantcast
Channel: Questions in topic: "gun"
Viewing all articles
Browse latest Browse all 592

Gun is not shooting? Please Help!

$
0
0
My gun script for my multiplayer game does not work? is there something that i am doing wrong? Code: using UnityEngine; using System.Collections; public class Shoot : MonoBehaviour { public GameObject bullet_prefab; float bulletImpulse = 50f; float delay; // Use this for initialization void Start () { } // Update is called once per frame void FixedUpdate () { if(Input.GetButtonDown("Fire1") && delay <= Time.time) { Camera cam = Camera.main; GameObject thebullet = (GameObject)Instantiate(bullet_prefab, cam.transform.position + cam.transform.forward, cam.transform.rotation); thebullet.rigidbody.AddForce(cam.transform.forward * bulletImpulse, ForceMode.Impulse); delay = Time.time + 1.0f; //change 1.0f to the delay you want } } void OnGUI(){ GUI.Box(new Rect(Screen.width/2,Screen.height/2, 10, 10), ""); } } Please Help! Thanks, Micky2171 EDIT: UPDATED SCRIPT: using UnityEngine; using System.Collections; public class Shoot : MonoBehaviour { public GameObject bullet_prefab; float bulletImpulse = 50f; float delay = 0 ; // Use this for initialization void Start () { } // Update is called once per frame void FixedUpdate () { if(Input.GetButtonDown("Fire1") && delay <= Time.time) { Camera cam = Camera.main; GameObject thebullet = Instantiate(bullet_prefab, cam.transform.position + cam.transform.forward, cam.transform.rotation); thebullet.rigidbody.AddForce(cam.transform.forward * bulletImpulse, ForceMode.Impulse); delay = Time.time + 1.0f; //change 1.0f to the delay you want } } void OnGUI(){ GUI.Box(new Rect(Screen.width/2,Screen.height/2, 10, 10), ""); } }

Viewing all articles
Browse latest Browse all 592

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>