- Home /
Question by
intrikit · Jun 11, 2013 at 09:26 AM ·
inputshootingprojectile
I have a script for shooting but when I apply it to a GameObject, there is no "Projectile" input where I can plug in my prefab bullets.
This is the script:
var projectile : Rigidbody; var speed = 20;
function Update () {
if ( Input.GetButton ("Fire1")) {
clone = Instantiate(projectile, transform.position, transform.rotation); clone.velocity = transform.TransformDirection( Vector3 (0, 0, speed));
Destroy (clone.gameObject, 3);
}}
Comment
Answer by ahaykal · Jun 11, 2013 at 09:56 AM
Next time please tell us where the error is...
Your problem is in this line :
clone = Instantiate(projectile, transform.position, transform.rotation); clone.velocity = transform.TransformDirection( Vector3 (0, 0, speed));
you have to put a var before clone:
var clone = Instantiate(projectile, transform.position, transform.rotation); clone.velocity = transform.TransformDirection( Vector3 (0, 0, speed));
Don't forget to mark it as closed.
Your answer
![](https://koobas.hobune.stream/wayback/20220613103938im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Shooting projectiles once per second. 1 Answer
Projectile Shooting Problem 1 Answer
How to fire projectile in direction character is facing? 3 Answers
Gun Fire, sparks on Collision 1 Answer
How can I shoot at enemies while facing left and right? 0 Answers