I’m making an fps game and as you probably know, shooting is the most important part of the game. I didn’t know how to do this so I looked it up on YouTube. I found Quill18’s fps tutorial and I was able to shoot. It made it so the bullet comes from the main camera but I want it to come from the gun. Can someone help me with this?
The gun object in the game is called “pistol”
using UnityEngine;
using System.Collections;
public class FP_Shooting : MonoBehaviour {
public GameObject Bullet_prefab;
float grenadeImpulse = 500f;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
if (Input.GetButtonDown ("Fire1") ) {
GameObject gun = GameObject pistol;
GameObject thegrenade = (GameObject) Instantiate (Bullet_prefab, gun.transform.position + gun.transform.forward, gun.transform.rotation);
thegrenade.rigidbody.AddForce (gun.transform.forward * grenadeImpulse, ForceMode.Impulse);
}
}
}