- Home /
Simple Shoot script
I'm using for my grappling gun--
var projectile : Rigidbody;
var speed = 20;
function Update () {
if ( Input.GetButton ("Fire1")) {
Instantiate(projectile, transform.position, transform.rotation);
velocity = transform.TransformDirection( Vector3 (0, 0, speed));
if ( Input.GetButton ("Fire2"))
Destroy;
}
}
Theres probably several errors in here but what i actually need help on is getting this java script for my gun to destroy the projectile after it was spawned but with the click of a button preferably the right click. How would go about typing JUST that part of da script the above is my attempt. DO ask questions on anything else not understood I will tell you what it is I am doing.. x)
-johnny
Answer by Fr0sZ · Jun 13, 2011 at 07:29 PM
if ( Input.GetButton ("Fire1"))
{
//you need to assagin the object to a varible so you can destory it later
var clone : GameObject = Instantiate(projectile, transform.position, transform.rotation); velocity = transform.TransformDirection( Vector3 (0, 0, speed));
}
if ( Input.GetButton ("Fire2"))
{
Destroy(clone);
}
this is the same script but slightly modified. I'm getting an error message saying "Definition of 'Shoot.laserPrefab' whose type could not be resolved because of a cycle. Explicitly declare the type of either one to break the cycle."
var laserPrefab = laserPrefab;
function Update ()
{
if ( Input.GetButton ("Fire1"))
{
//you need to assagin the object to a varible so you can destory it later
var clone : GameObject = Instantiate(laserPrefab, transform.position, transform.rotation); velocity = transform.TransformDirection( Vector3 (0, 0, speed));
}
if ( Input.GetButton ("Fire2"))
{
Destroy(clone);
}
}
how do I fix it?
if you're going to post code, format it
This isn't an answer. The answer space should be reserved for answers only. If you have a question or comment on a particular post here, add a comment in the correct spot. If you have another question, open one of your own.
Answer by JohnnyD · Jun 13, 2011 at 07:27 PM
Oh I'm so sorry, PLEASE help me. It'd be much appreciated
Don't post comments as answers. Why? Well, because answers are for well, answers.
Your answer
Follow this Question
Related Questions
Grappling Gun Help (shoot scripting help) 1 Answer
Character too floaty after jumping and grappling.,Grapple too floaty 0 Answers
How do i make a simple grappling hook? 0 Answers
2D grappling hook problems 1 Answer
grappling hook help 0 Answers