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 helios51193 · Apr 21, 2019 at 09:14 AM · scripting problemgamebestpractices

Propogate upgrade to different entities (Wepon upgrade System)

I am making a top down shooter with an upgrade system. In The game,Every bullet has a "Damage" variable which tells how much damage it will do to the player. My question is what would be the best practice to apply the upgrade. Should the bullet query the "Game manager" about the upgrade and change its damage accordingly or if the gun should set the value everytime a bullet is fired ?

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
1
Best Answer

Answer by KevRev · Apr 21, 2019 at 12:16 PM

There's dozens of different ways you could do this, and your method could depend on how you instantiate the bullets in the first place.

I'll make up some theoretical variables, you can probably follow the logic and make something similar if you find it useful.

So firstly, lets do some initialisation:

 **Player class**
 public static int currentWeapon;
 
 **Weapons class**
 public static List<Weapon> weapon = new List<Weapon>(5);
 
 public Weapon ()
 {
     public GameObject Model;
     public int Damage;
 }

 Start()
 weapon[0].Model={your weapon 1 prefab};
 weapon[0].Damage=10.0f;
 weapon[1]={your weapon 2 prefab};
 weapon[1].Damage=20.0f;
 weapon[2]={your weapon 3 prefab};
 weapon[2].Damage=30.0f;
 weapon[3]={your weapon 4 prefab};
 weapon[3].Damage=40.0f;
 weapon[4]={your weapon 5 prefab};
 weapon[4].Damage=50.0f;
 
 In your firing bullets code:
 GameObject bullet = Instantiate(Weapons.weapon[Player.currentWeapon].Model);

 In your OnCollision code:
 
 OnCollission (Collider col){
 shields -= col.transform.GetComponent<Weapon>().Damage;
 }

This is a kinda high level overview of the logic I would suggest, not necessarily all working code as i've just written it off the top of my head.
But I think it'll give you something to work on.

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 helios51193 · Apr 21, 2019 at 12:32 PM 0
Share

Thanks for the reply.I have figured out that part actually.I may not have structured my question correctly but my question is that i have a upgrade system which increased the damage of the wepon.For example, for every level increase the damage is increased by 10%.How will i tell every bullet that the their damage has increased and they have to damage player more ?

Also, regarding the code :- is the OnCollision you are referring is on the wepon or on the player ?

avatar image KevRev helios51193 · Apr 21, 2019 at 01:18 PM 0
Share

I would just add a public float $$anonymous$$ultiplier; to the Weapon class.

By default it should be 1.0f;

Each time you collect a powerup, perform:

 weapon[n].$$anonymous$$ultiplier+=0.1f;

Each time you die, set it to 1;

Then change your collision logic to:

 Weapon bullet = col.transform.GetComponent<Weapon>();
 shields -= bullet.Damage * bullet.$$anonymous$$ultiplier ;

And this collision logic should be placed on anything you can hit with the bullets (enemies / obstacles).

avatar image helios51193 KevRev · Apr 21, 2019 at 02:15 PM 0
Share

Thanks for the answer and very fast at that.It gave me some idea about how to proceed.

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

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

Related Questions

Out of memory during play 0 Answers

How do I get enemies to only chase me in certain areas 0 Answers

How can I un-invert my first person spaceship controls in C#? 1 Answer

Programming the Judgement Wheel (Shadow Hearts) 0 Answers

How to create script linked to scene? 2 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