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 john-essy · Dec 07, 2011 at 01:55 PM · weapon system

Weapon system with a class

The question i have is. I have a class with all possible things i will need for the weapon how would i go about creating an index of these weapons and select them with the mouse scroll wheel and only allow them to be selected if they have been bought here is my code and it is literally just the weapon class i hope someone can point me in the right direction
var gunList : Gun[];

 class Gun
 
 {
 
     var name : String;
     var isSelected :  boolean;
     var canUserShoot :  boolean;
     var shootForce :  float;
     var ammo : int;
     var bullet :  GameObject;
     var bullet2 : GameObject;
     var bullet3 : GameObject;
     var bulletHolder1 : Transform;
     var bulletHolder2 : Transform; // only use these if the gun has more then one barrel
     var bulletHolder3 : Transform; // only use these if the gun has more then one barrel
     var shootSound : AudioClip;
     var cost : int;
     var unlocked : boolean;
     var shootEffect : Transform;
     var fireRate : float;
     var currentWeapon : int;
     var weaponModel : Renderer;
 
 }
 
 
 
 function NextWeapon()
 
 {
 
 }
 
 function PreviousWeapon()
 
 {
 
 }     
 
 function SwapWeapon()
 
 {
 
 }
 
 
 
 // i dont know if this is possible but create and index of the weapons and say something like raygun = 1 then when the player uses the mouse scroll wheel increase the number
 
 // Then when it gets to the max reset the number to 1 which will be the raygun 
 
 // We also need to disable the renderer of unused guns 
 
 // and make sure that only the correct values for the guns are used. No point in having a rocket launcher the firs rockets and lasers would be pretty cool though:)





 
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 Justin Warner · Dec 07, 2011 at 06:26 PM 0
Share

Please select all your code and push the 1010101 button to code it for us next time =).

As for the question, check out the Input methods in the API they have stuff on the mouse wheel (I believe).

avatar image john-essy · Dec 07, 2011 at 11:31 PM 0
Share

I did use the 10101 button i think it is chrome as it only happens with that. I have looked into the API and found info about the mouse it's just i am new to indexing things like weapons and so forth. Thanks

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by Justin Warner · Dec 08, 2011 at 05:03 AM

Well, you have your array of gun's. Now make a variable for position in that array.

On Input scroll wheel up, increase that position, (On Update() check if it's = to length, if so, reset to 0, also check if it's

To get this Input, we look at the API. However, because this "could" be weird, I'll just Google:

https://www.google.com/search?rlz=1C1GGGE_enUS456US456&gcx=c&sourceid=chrome&ie=UTF-8&q=unity3d+scroll+wheel+input

So from this, we get: http://answers.unity3d.com/questions/26649/scrollwheel-input-not-detected-in-script.html

Now, we have our axis.

So simply, in the Update() put in the if input is scrollwheel up, do this, if down, do that.

Now, whether it goes up or down, that same search got us: http://answers.unity3d.com/questions/13485/implementing-the-scrollwheel.html

From here, we can see positive = up, negative = down, so now you can solve the rest by yourself.

Just walked you through basically how to answer most any questions =).

Hope this helped! Have a good night!

Comment
Add comment · 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

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

`DecalMode' could not be found 1 Answer

Animating different Weapons 2 Answers

Replacing Weapon 2D Shooter Unity 1 Answer

Cycling Weapons, using C# int string problem 1 Answer

Weapons that used to work got broken after update - has StopAllCoroutines() stopped working? 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