- Home /
How to make a gun shoot.
Here's my code:
public var bullet = Rigidbody;
public var speed : int = 10;
function Update () {
if (Input.GetButtonDown("Fire1")) {
var clone = Rigidbody;
clone = Instantiate(clone: bullet, transform.position, transform.rotation);
clone.velocity = transform.TransformDirection(Vector3(0,0,speed));
}
}
The thing is that it's saying there's no instance for it.
I look at the proper syntax and it says "Instantiate(original: UnityEngine.Object...);"
The trouble is I don't know what original means. I've been trying to put things in it's place, no success.
Thanks.
$$anonymous$$aybe THIS VIDEO TUTORIAL will help you! To be clear it is not my video, it is Brackeys' BRAC$$anonymous$$EYS' YOUTUBE CHANNEL
Answer by _1 · May 05, 2014 at 10:42 PM
public var bullet : Rigidbody;
public var speed : int = 10;
function Update () {
if (Input.GetButtonDown("Fire1")) {
var clone : Rigidbody;
clone = Instantiate(bullet, transform.position, transform.rotation) as Rigidbody;
clone.velocity = transform.TransformDirection(Vector3(0,0,speed));
}
}
try this, you shouldn't have the clone equal to a component like the rigidybody and in the first parameter of Instantiate(), don't try to declare a variable, just say what you are creating like this Instantiate(bullet), and in the, "as" statement that just makes it instantiate as a rigid body. If you don't want that to happen, delete the "as rigidbody" part. Hope this helps and best of luck
Your answer
Follow this Question
Related Questions
How to make a gun work with camera? 1 Answer
How can I make an object always look at the mouse? 2 Answers
How to rotate gun only on X and Y axis? 1 Answer
DmC: Devil May Cry Dual Shot? 0 Answers
How to make a bullet spread 1 Answer