Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 unity_i0W6HQ-YEHqs4Q · Nov 12, 2019 at 10:37 PM · scripting problemweaponupgrade

how to make an upgrade interface

Hey I'm working on a game where you can upgrade the main weapons damage, fire rate, and the explosion radius of the bullet with skill points that you gain after every round and I'm not really sure where to start with the scripting I already have a menu for it just not sure how to fit everything together.

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

1 Reply

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

Answer by Cornelis-de-Jager · Nov 12, 2019 at 10:37 PM

Ok I haven't done one before, but lets brain storm this;

Firstly, you'll need a class to actually handle everything. So lets make a static class that you can use from anywhere.

 // We'll make this static so it can be referenced from anywhere
 public class UpgradeInterface : MonoBehaviour {

     // Variables
     private static UpgradeInterface _isntance;
     public static UpgradeInterface UpgradeInterface { get { return _isntance; }}

     private void Awake()
     {
         if (_instance != null && _instance != this)
         {
             Destroy(this.gameObject);
         } else {
             _instance = this;
         }
     }
     
     // Additional Code Goes here
 }

usage:

 UpgradeInterface.ExampleFunction();

Well whats the first thing you need to do when you want to upgrade? Open the menu ofcourse... When you open the menu you need to load the data you are going to use. So write a peice of code that will fetch and send it to a script that will control the upgrading. We'll just add it to the script above:

 // More Variables
 GunStats gunStats;
 
 // Load function
 public void loadMenu (GunStats gunStats) =>
     this.gunStats = gunStats;

usage:

 // Note gun stats are the current stats on your gun
 UpgradeInterface.loadMenu(gunStats);
 

Now that stats are loaded. But you also need logic to decide how many points are available to spend. So lets add a variable and function to add points;

 // More Variables
 private int upgradePoints = 0;
 
 // Add points function
 public void AddPoints (int points) =>
     upgradePoints == points;
 
     

Almost done with the script. The next thing we need now is the ability to actually increase and decrease the stats. You'll have to make a function for each attribute of the gun. Below we'll only add one attibute, the damage one. Currently it onyl increases, but you can later pass down a variable if you want it increase and decrease.

 // Increase Damage Attibute - simply adding one point
 public void AddDamage(){
     if (upgradePoints > 0){
         this.gunStats.Damage++;
         this.upgradePoints--;
     }
 }
     

After this is done you need to link the UI to the scripts. At this stage you are able to upgrade your gun... but now thats its upgraded you need to return the gunStats and make it permanant; The following function should be called when you are done upgrading the stats.

 // get the stats after done upgrading.
 public GunStats GetCurrentGunStats () => gunStats;
     

Technically you are done now. But lets add some feedback functions so we can see how many points we have left to spend.

 // Get Poitns Left
 public float GetUpgradePointsLeft ()  => upgradePoints;
 

now the hardest park will be hooking up the UI since it is just tedious. But the basic flow of this class should look like;

 // Click to open menu
 ==> loadMenu
 
 // Click on buttons to add points if you have available
 => AddAttribute()
 => AddAttribute()
 => AddAttribute()
 
 // Click done
 ==> GetUpgradePointsLeft
 

This is a very simple menu system, but can be expanded from here.

Comment
Add comment · Show 9 · 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 unity_i0W6HQ-YEHqs4Q · Nov 12, 2019 at 11:29 PM 0
Share

when i try public static UpgradeInterface UpgradeInterface { get { return _isntance; }} I get an 'UpgradeInterface': member names can not be the same as their enclosing type error

avatar image yashetv unity_i0W6HQ-YEHqs4Q · Nov 12, 2019 at 11:33 PM 0
Share

Remove ": $$anonymous$$onobehaviour"

avatar image unity_i0W6HQ-YEHqs4Q yashetv · Nov 12, 2019 at 11:50 PM 0
Share

still doesn't work

avatar image Cornelis-de-Jager unity_i0W6HQ-YEHqs4Q · Nov 13, 2019 at 06:32 AM 0
Share

I just tried and tested it. Plus this is a know pattern, can you please post your code here.

avatar image evilkinght Cornelis-de-Jager · Nov 13, 2019 at 07:22 PM 0
Share

same person btw just changed my name

Show more comments

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

206 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 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 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 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 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 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 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 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 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 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 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 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 avatar image avatar image

Related Questions

What is the unity reference helper script? 1 Answer

Weapon switching with an animator and script. 0 Answers

I cant add scripts to my weapons,i can't add Scripts to my weapon 1 Answer

Setting gameobject to null 1 Answer

Different bullet effect on different physics materals. 1 Answer


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