- Home /
Need help with my gun script!
I made a shooting script but when I shoot the gun it shoots really fast and it shoots a lot of bullets at once. I only want it to shoot one bullet every time. Here is my script.
using UnityEngine;
using System.Collections;
public class Shoot : MonoBehaviour {
public Rigidbody bulletPrefab;
public Transform spawnPoint;
public int speed;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
if(Input.GetKey(KeyCode.Mouse0))
{
Rigidbody bulletInstance;
bulletInstance = Instantiate(bulletPrefab, spawnPoint.position, Quaternion.identity) as Rigidbody;
bulletInstance.AddForce(spawnPoint.forward * speed);
}
}
}
And could somebody tell me how to make it where the bullet doesn't go on it's side. When I shoot the bullet goes forward but the bullet will face down.
Answer by tw1st3d · Oct 27, 2013 at 09:12 PM
"Quaternion.identity static Quaternion identity; Description
The identity rotation (Read Only). This quaternion corresponds to "no rotation": the object."
Try doing this:
bulletInstance = Instantiate(bulletPrefab, spawnPoint.position, bulletPrefab.transform.rotation) as Rigidbody;
This is good for my rotation problem. Thank you very much!
Your answer
Follow this Question
Related Questions
Setting bullet instansiate direction? help? 1 Answer
Bullets aren't firing / Bullet holes not instantiating correctly 0 Answers
how to create a gun in unity3d 2 Answers
Control amount of bullets 2 Answers
Make a Gun fire multiple times 3 Answers