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 /
This question was closed Jan 23, 2015 at 08:06 AM by fafase for the following reason:

Duplicate Question

avatar image
0
Question by JustinC · Jan 23, 2015 at 07:46 AM · gameobjectdestroykillarmorhealth

Destroy (gameObject) Help

I am trying to make practice orbs to shoot at, when armor reaches 0 they should be destroyed. Problem is, once you kill one orb, they all die. Here is my rough armor script that is attached to each practice orb:

 public GameObject Target;
     public int armor;
 
     public static int armorRating;
     public static int currArmor;
 
     void Start () 
     {
         armorRating = armor;
         currArmor = armorRating;
     }
 
     void Update () 
     {
         if(currArmor <= 0 )
         {
             Destroy(gameObject);
             Debug.Log("Practice Item Destoyed");
         }
     }
 
     public static void TakeDamage (int amount)
     {
         currArmor -= amount;
         Debug.Log (currArmor);
     }


I cannot seem to figure out where I am going wrong, any help would be greatly appreciated. Thank you

Comment
Add comment · Show 1
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 fafase · Jan 23, 2015 at 08:07 AM 0
Share

I am closing that question as it falls into the already full bucket of GetComponent/Static/Script interaction questions.

Have a little faith in you, find them and read them.

1 Reply

  • Sort: 
avatar image
0
Best Answer

Answer by Andres-Fernandez · Jan 23, 2015 at 07:38 AM

Just remove the static modifier from your currArmor variable (and google it, since it seems you are not using it properly)

Comment
Add comment · Show 3 · 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 JustinC · Jan 23, 2015 at 07:52 AM 0
Share

currArmor has to be static because I call it in my TakeDamage function which is static, and TakeDamage has to be static so that I can enter the damage amount from the bullet. or am I doing that wrong as well?

avatar image Andres-Fernandez · Jan 23, 2015 at 07:56 AM 0
Share

The function doesn't need to be static (if it's public, then it can be called from any other script). And the variable can't be static, since a static member will be shared by all instances of the class, therefore all your orbs will share the same currArmor value (you decrease the value in one orb, but all orbs share the same value...). Check here.

avatar image JustinC · Jan 23, 2015 at 08:09 AM 0
Share

Thanks for your help I was understanding statics wrong i will have to change a few other scripts now but it worked great!

Follow this Question

Answers Answers and Comments

3 People are following this question.

avatar image avatar image avatar image

Related Questions

using Contains(gameObject) to find and destroy a gameObject from a list 2 Answers

Why does this do nothing (Health Script) 2 Answers

Destroy all GameObjects EXCEPT some... 2 Answers

Destroyed gameobject found with FindObjectsOfType<>? 1 Answer

Collect and Use Object 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