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 pickle chips · Jul 25, 2013 at 01:51 AM · guichangeclicktarget

Hitmarker appears on both targets

So I know what my problem is, but after hours of trying to fix it I can't think of a way to do it. So when I attack the enemy (or target), the GUI is drawn on the target saying the amount of damage. But if I change targets (by clicking on a different enemy) while the hitmarker is still being shown, it then shows on the new target, not the one that actually took the damage. How can I prevent this?

Here is my code: public void showHitMarker() { Vector3 v3pos = Vector3.zero;

         if (target) {
             v3pos = target.transform.position;
             v3pos = Camera.main.WorldToScreenPoint(v3pos);
             v3pos.y += 25;
             v3pos.y = Screen.height - v3pos.y;
             v3pos.x -= 25;
         }
 
         
         if (showDamage > 0) {
             if (!target)
                 showDamage = 0;
             
             GUI.Label(new Rect(v3pos.x, v3pos.y, 50, 50), damage.ToString(), hitMarker);
             showDamage -= Time.deltaTime;
         }
     }

As you can see, when i switch to a new target it would make sense that it is drawn on the new one. I've tried storing the right target to draw it on in a variable but I can't figure out how to do that properly...

Any ideas? Thanks

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

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

Answer by oddeven · Jul 25, 2013 at 02:23 AM

I would suggest restructuring things a bit. Think about creating a HitDamageScript that you attach to objects when you hit them. The script would render the damage for some time and then destroy itself. You can move the render logic you have now to OnGUI of HitDamageScript. In your hit detection logic add something like:

 // assuming target is a GameObject
 HitDamageScript script = target.AddComponent<HitDamageScript>();
 script.SetDamage(X); // where X is the amount of damage caused
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 pickle chips · Jul 25, 2013 at 12:06 PM 0
Share

I like this idea, I'll try it out tonight

avatar image pickle chips · Jul 25, 2013 at 10:44 PM 0
Share

I didn't use your exact idea, but I did reconstruct it a bit, and i will accept your answer because it's what gave me the idea. I just put the hitmarker part in the enemyHealth script and not in the playerAttack script, so when the enemy takes damage it shows the hitmarker.

avatar image oddeven · Jul 26, 2013 at 01:20 AM 0
Share

very nice, glad to help!

avatar image
0

Answer by Trey3Stone · Jul 25, 2013 at 02:19 AM

Try setting showDamage = 0 at the point where you change target.

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

17 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

Related Questions

Passing values between scripts 5 Answers

Moving Target Circle 2 Answers

click on GUI button goes through to a collider... 0 Answers

FBX Animation Import 2 Answers

make GUI not overlap? 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