- Home /
Fps Gun Scrpt :)
I'm making a FPS i attached a game object to the main camera of a first person controller the game object is to serve as a spawn point to the gun but when i move the camera up and down in the game the spawn point doesnt move i attatched it using parenting here's my script please help thanks
#pragma strict
var bullitPrefab:Transform;
var perShotDelay = 0.15;
private var timestamp = 0.0;
private var spawn : Transform;
function Start() {
spawn = GameObject.Find("spawn").transform;
}
function Update() {
if(Input.GetMouseButton(0) && Time.time > timestamp) {
timestamp = Time.time + perShotDelay;
var bullit = Instantiate(bullitPrefab, spawn.position,Quaternion.identity);
bullit.rigidbody.AddForce(transform.forward * 50000);
}
}
Comment
Answer by Jun yan · Dec 22, 2014 at 07:45 AM
#pragma strict
var bullitPrefab:Transform;
var perShotDelay = 0.15;
var spawn :GameObject;
private var timestamp = 0.0;
function Start() {
}
function Update() {
if(Input.GetMouseButton(0) && Time.time > timestamp) {
timestamp = Time.time + perShotDelay;
var bullit = Instantiate(bullitPrefab, spawn.transform.position, spawn.transform.rotation);
bullit.rigidbody.AddForce(transform.forward * 1000);
}
}
Set your muzzle/the place bullet come out to spawn... C:
Your answer
![](https://koobas.hobune.stream/wayback/20220613123440im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Problems with Classes...i think 1 Answer
Gun Manager only working once 1 Answer
pick up ammo from specific gun? 1 Answer
arms with gun and animation 1 Answer