Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by GreenGuy92 · Oct 28, 2013 at 11:28 AM · rigidbodybulletshooter

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.

Comment
Add comment · Show 2
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image ahaykal · Oct 28, 2013 at 12:48 PM 0
Share

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).

avatar image Owen-Reynolds · Oct 28, 2013 at 03:36 PM 0
Share

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.

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

17 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

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


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges