- Home /
Question by
Snowglider · Sep 11, 2012 at 01:11 AM ·
shootingprojectileselectionselecting
Trouble with selective projectile script
Here is what I was hoping would happen. By default, the empty_object will shoot my crate rigid body when the mouse is clicked. BUT, if "2" is pressed at any time, than the object to be fired will be my earth object. And again if "1" is pressed the crate is reselected. Nothing visible is happening in-game, what did I mess up? And I do have object1 and object2 defined in unity, so thats not it.
var object1 : Rigidbody;
var object2 : Rigidbody;
function Update () {
var projectile : Rigidbody;
var select = 1;
if (Input.GetButtonDown("1") == true) {
select = 1;}
else if (Input.GetButtonDown("2") == true) {
select = 2;}
if (Input.GetButtonDown("Fire1") == true && select == 1) {
projectile = Instantiate(object1, transform.position, transform.rotation);
projectile.name = "Crate";
projectile.velocity = transform.TransformDirection (Vector3.forward * 4000 * Time.deltaTime);}
else if (Input.GetButtonDown("Fire1") == true && select == 2) {
projectile = Instantiate(object2, transform.position, transform.rotation);
projectile.name = "Earth";
projectile.velocity = transform.TransformDirection (Vector3.forward * 4000 * Time.deltaTime);}
}
Comment
Your answer
Follow this Question
Related Questions
Shooting in 2 dimensional games 2 Answers
Gun Fire, sparks on Collision 1 Answer
Cannon shoots in wrong direction with unrealisic Physic 1 Answer
Problem with Ammo/Shoot script 2 Answers