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 cj13810 · Jun 28, 2012 at 08:36 PM · weaponpickup

weapon pickup

how would I make my gun locked and then unlocked when I collide with an object. I have my weapon switch script done but I don't know how I would make it so the player cant use it until they collide with an object.

here is my weapon switch script it is done in Java script

 private var RifleEquip = true; 
  
  
  function Start () 
  {
      SelectWeapon(0);
  }
  
  
  function OnGUI() {
     // if (GUI.RepeatButton (Rect (85,Screen.height - 80,75,75),
      "Shoot")) {
       //   BroadcastMessage("Fire");
     // } 
      if (RifleEquip==true)   {
      if (GUI.Button (Rect (Screen.width - 210,5,50,75), " ")) {
         SelectWeapon(1);
         RifleEquip = false;
      }
      }
      if (RifleEquip==false) {
      if (GUI.Button (Rect (Screen.width - 210,5,50,75), " ")) {
         SelectWeapon(0);
         RifleEquip = true;
      }  
      }
   }
   function SelectWeapon (index : int) {
       for (var i=0;i<transform.childCount;i++)   {
          if (i == index)
            transform.GetChild(i).gameObject.SetActiveRecursively(true);
          else
            transform.GetChild(i).gameObject.SetActiveRecursively(false);
       }
   }
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 whydoidoit · Jun 28, 2012 at 08:44 PM 0
Share

Format your code by indenting 4 space or 1 tab before pasting or by selecting it and hitting the code button after pasting. Don't use \> to format code.

avatar image whydoidoit · Jun 28, 2012 at 10:00 PM 0
Share

I fixed it for you this time :)

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by whydoidoit · Jun 28, 2012 at 10:03 PM

Do this:

  • Attach a rigidbody (set to isKinematic false if you don't want physics) to your character

  • Have a collider on your character

  • Have a collider set to isTrigger = true on the item you need to touch

  • Set the tag of the touchable item to weapon activate

  • Write an OnTriggerEnter function on your character and check for the touch tag. If you find it set fireable to true.

  • Write an OnTriggerExit function for your character and check for the touch tag and set fireable to false.

  • Use the fireable boolean to turn on your buttons.

Comment
Add comment · Show 4 · Share
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 cj13810 · Jun 28, 2012 at 10:29 PM 0
Share

do you mean to add the OnTriggerEnter function to my already existing script or to make a new script?

avatar image whydoidoit · Jun 28, 2012 at 10:31 PM 0
Share

You can add them to the current one, should be fine.

avatar image cj13810 · Jun 28, 2012 at 10:38 PM 0
Share

where would I put them

sorry for being a complete noob to progra$$anonymous$$g

avatar image cj13810 · Jun 29, 2012 at 12:52 AM 0
Share

I still need some help

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Multiple Cars not working 1 Answer

problem with weapon animation -.- 0 Answers

How would go about making a weapon pick up? 3 Answers

Very simple picking up items script? 2 Answers

Need help with picking up items by typing "E" 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