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 /
This question was closed Jan 25, 2018 at 07:27 AM by unity_S0ZCLiVP1XXH-w for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by unity_S0ZCLiVP1XXH-w · Jan 24, 2018 at 10:36 PM · variablevariablesint

Problem with variables,Problem with identifying a variable

I have one variable that I send to another script. And here I have a problem: this variable is displayed as two different . So I don't know why it happens and what can I do ...alt text public class HealthScript : MonoBehaviour {

     public int curHealth;
         
     public bool CanGetHit;
 
     
 
     
     void Start()
     {
         CanGetHit = true;
 
         curHealth = 100;
 
        
     }
 
      
 
     void OnTriggerEnter(Collider col)
     {
         if (col.tag == "Spear" && CanGetHit == true)
         {
             col.gameObject.GetComponent<DamageSc>().Damage = damage;
             Hited(damage);
         }
     }
 
 
 
    void Hited(int damage)
     {
         if (CanGetHit == true)
         {
                         
             curHealth = curHealth - damage;
 
            
             CanGetHit = false;
             
         }
 
 
     }
 
 }


, ![alt text][2]

снимок-экрана-84.png (52.3 kB)
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

2 Replies

  • Sort: 
avatar image
0

Answer by Honorsoft · Jan 24, 2018 at 11:57 PM

I'm a little confused because you say "this variable is displayed as two different", so I'm not sure exactly what that means or which "this" variable refers to, but.. One thing I noticed is in your line col.gameObject.GetComponent<DamageSc>().Damage = damage; it looks like you are trying to get the amount of damage that the weapon that collided with the character does, in that case, I think you meant: damage = col.gameObject.GetComponent<DamageSc>().Damage; and you would have to declare a public int damage; at the top of this object's script. The way you had it, the col.gameObject's Damage was being set to this object's damage(which in this script stays at zero) Also, you will need to reset the 'CanGetHit' to true after a bit of time passes.

-It might help for us to see your weapon object's Damage script too.

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

Answer by unity_S0ZCLiVP1XXH-w · Jan 25, 2018 at 07:26 AM

I did as you said and it all worked. Thank you! Problem solved

Comment
Add comment · Show 1 · 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 Honorsoft · Jan 25, 2018 at 10:03 PM 0
Share

no problem, it gets confusing, but usually if you go 'line by line' through a script, checking what happens to the variables, you can see the problem...it just takes longer..lol

Follow this Question

Answers Answers and Comments

78 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

Related Questions

How to reset a variable? 1 Answer

Pass a function(float) as variable 2 Answers

Transfering Variables Between Sections [SOLVED] 2 Answers

How to write "if (var int = var int 2)" ? 1 Answer

[C# Code] Why am I getting this error??? 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