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 /
  • Help Room /
avatar image
0
Question by fredmiller12345 · May 25, 2016 at 03:15 AM · c#texturesscore

Score Points based on Animating Png Texture

Hi.... I have a 3d object and I have it changing(animating) png textures from 100 pts to 200 pts to 300 pts, etc. When I touch the 3d Object I want it to score whatever the png texture is at that moment... so if it is animating and you touch 300 pts... Boom 300 pts is added to score... Wondering if anybody has any ideas on how to make this happen... Code is in c-sharp... 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

Answer by Alec-Slayden · May 25, 2016 at 07:51 AM

While it would help to see the code, I assume the score object has a monobehaviour on it that is changing the PNG. I would add an integer that represent the score to that script. When the script changes the texture, it should also change that integer.

If this is the only object in your scene that does this, then your score script can reference the object in the inspector and you can make that integer public, for simplicity.

Otherwise, if you have a lot of these and so can't be sure which one was clicked, there are a couple options. For all of them, I recommend using an EventTrigger component on the object, with a pointer click event that targets a method on that same script (make sure you have a unity event system with touch / mouse event components as required, and a physics raycaster on the appropriate camera)

From there, you have a few options. Lets say the name of the actual score calculation script is "scorekeeper", and lets say the animated objects are "bonus items": 1) Have a public static method in your scorekeeper script that the bonus items can call when they are clicked, sending their private integer as a parameter

2) Implement your scorekeeper as a singleton and have the bonus items call a public method on that instance when they are clicked. This is kind of an overkill extension of the implementation of 1. You should avoid it unless you need to access the scorekeeper in a lot of ways all over the place or you have to ensure for some reason that there is only one.

3) Use a static EventHandler on the bonus item script that is published when a bonus item is clicked. Have your scorekeeper subscribe to that event handler. This is particularly good if you need other things to be able to listen to what bonus item was clicked, however it requires extra care in cleaning up your subscriptions. It's worth it if you're comfortable with C# events.

4) Find the scorekeeper in the bonus items awake, using FindObjectOfType and store it in a private field. Then call a public method when the bonus item is clicked. I recommend against this method since I never like Find use (it's slow), and managerial references are not usually the best option in my opinion (they feel like they go against code flow).

I'm sure there are more and potentially better options, but those are the ones that come immediately to mind that let you keep the bonus items as self-encapsulated prefabs

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 fredmiller12345 · May 25, 2016 at 05:49 PM

Wow! Thanks for your detailed answer... Let me digest it and reply back.... Thanks again... Fred

Comment
Add comment · Show 2 · 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 fredmiller12345 · May 25, 2016 at 06:25 PM 0
Share

Hi Alec... Just wondering if I might be able to share my code with you through email... If so, my email is ravenger1@aol.com... If not... No prob... Best regard,,, Fred

avatar image Alec-Slayden fredmiller12345 · May 25, 2016 at 10:17 PM 0
Share

I've emailed you

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

159 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

Related Questions

NullReferenceException: Object reference not set to an instance of an object 1 Answer

Healthbar creation without using UI, only with images/TEXTURE 0 Answers

Difference between ''(Texture)'' and ''as Texture'' 1 Answer

Highscore and PlayerPrefs unity C# 1 Answer

Highscore table C# HELP!!! 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