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 Shire_ · Apr 21, 2016 at 01:58 PM · collisiontextnoobvalue

Coin value is doubling on some scenes and not others?

I have made a prefab with a coin value of 5. It is picked up as the player collides with the coin and a score displayed on the canvas.

However, on some scenes the coin value is doubled for some reason (instead of recording a score of , a score of 10 is recorded instead) which is not intended.

I have tried deleting the coins/ prefab but when ever a new coin is added to the same scene it always doubles the value???

CoinValue Script:

  public class CoinValue : MonoBehaviour {   
  
  public int value;  
  
  }

Score Script:

  public class ScoreManager : MonoBehaviour {

 public static int Money;


 Text ScoreCounter;

 void Awake()
 {
     ScoreCounter = GetComponent<Text>();

     Money = 0;
 }

 void Update()
 {
     ScoreCounter.text = "Score: " + Money;
 }

 }


Collision Script:

 public class CoinPickup : MonoBehaviour {

 void OnTriggerEnter(Collider col)
 {
     if (gameObject.CompareTag("Coins"))
     {
         Destroy(gameObject);

         ScoreManager.Money += gameObject.GetComponent<CoinValue>().value;
     }

 }
 }


All of these scripts are then added to the prefab coin under the tag Coins.

Any help on this would be great because I've tried a couple of different ways of counting the coins collected but the problem seems to persist.

Thanks for reading.

Comment
Add comment · Show 3
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 Dave-Carlile · Apr 21, 2016 at 01:59 PM 0
Share

Add some Debug.Log statements in various parts of your code so you can see how things are flowing. Often this sort of doubling thing is because you have your script on multiple objects or something. Logging will help you identify if that is the case.

avatar image Shire_ Dave-Carlile · Apr 22, 2016 at 09:37 AM 0
Share

hey, I added a debug.log for the CoinPickup script.
On the scenes where it doubles the value the debug instantly appears twice. so it seems to be registering that the coin is picked up twice. I have searched everywhere and I am confident the script has not been placed twice into the scenes that it occurs with.
do you have any other advise? the coin is a prefab i created in blender, could that have any effect on it?
Thanks @ Dave Carlile

avatar image Shire_ Shire_ · Apr 22, 2016 at 09:46 AM 0
Share

Ok, if I take the scene that works properly and then copy and paste all the assets from the scene that doesn't work then it still doubles meaning it must be tied to an in game object??? but I really cant find it, any suggestions?

1 Reply

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

Answer by Shire_ · Apr 22, 2016 at 10:03 AM

Fixed Script by replacing scripts attached to player in scenes where it was doubling.....

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Showing a restart screen on contact with an object and more... 1 Answer

Level Unlock System 0 Answers

How to detect the length of an input field [C# noob] 1 Answer

Arcade name input with two buttons 0 Answers

Why isn't my C# code sending updates to my text scoreboard? 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