- Home /
Preventing three game objects firing at once
Hey guys I'm doing a shooter assignment and I have three game objects with cameras attached to them. Ive made the space bar the button that will allow the player to shoot three different rigid body targets that the three cameras are near. I have also put a feature in that if the player right clicks they can switch between the cameras and with that come my issue. No matter what camera/game object im using if i press space bar all three game objects fire at the same time instead of just the one being used. So i was hopeing if any of you may know of a feature that would only allow the game object that is selected to fire and automatically switch off the other two from firing unless the player right clicks again and selects them ? sorry for the long winded question by the way here is my script so far
#pragma strict
var bullet : Rigidbody;
function Start ()
{
}
function Update ()
{
if(Input.GetKeyDown("space"))
{
//everything inside brackets runs
var latestBullet = Instantiate(bullet, transform.position, transform.rotation);
latestBullet.AddRelativeForce (0, 0, 100);
}
}
And my second question is i dunno why the bullets are so huge since i made the prebab scale of the bullet 0.1 , 0.1 , 0.1 yet the bullets are the size of melons. Any help would be greatly appreciated.
Use a boolean for when the current object is selected. If the bool is true then that particular object is used, turn the other bool false.. Then add to the if(Input.Get$$anonymous$$eyDown("space") && boolistrue).
Or, same idea as ahaylyal, have the fire IF check whether the camera is "on you" however you can. Suppose you're childing the camera to the active object. Could check:
if(spacePressed && transform==Camera.main.transform.parent)
If you are on object 1,2 or 3, then have firing check cameraNumber==myNumber.
Your answer
Follow this Question
Related Questions
Should I use raycasting or colliders? 1 Answer
Shooting in direction of mouse cursor 2d 5 Answers
Realistic Bow and Arrow Physics? 2 Answers
how to rotate to face camera point in 2D 2 Answers
Issue with Bullet Movement shooting 0 Answers