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 RustyHook · Jul 09, 2014 at 10:18 AM · prefabscore

Instantiated Prefabs resetting score and not detecting tap?

Hey, Im making a game where when you tap the objects (which are Randomly Generated ) that fall down the screen, a point is added, when the Prefab is cloned the 'Score'is resets to 0... Any help? heres the Score script added to my Prefab.

 using UnityEngine;
 using System.Collections;
 
 public class Score : MonoBehaviour {
 
     public Transform clicks;
     public GUIText score;
     public bool  clicked = false;
     public int click = 0;
     
     public void  Start (){
 
     }
     
     public void  Update (){
         score.text = "Pingas Popped: " + click;
         
         if (click == 250)
             Application.LoadLevel("Superman");
     }
     
     
     
     void  OnMouseDown (){
         click += 1;
     }
 
 }

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

1 Reply

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

Answer by Tehnique · Jul 09, 2014 at 10:50 AM

Each prefab has it's own score, which starts as 0. I don't know how you use this score, but it seems to me that it should be in only 1 place, not on all prefabs. As a simple solve, you could try to make "click" static (so only 1 value is shared by all score objects).

Comment
Add comment · Show 9 · 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 RustyHook · Jul 09, 2014 at 10:51 AM 0
Share

How could I $$anonymous$$ake "click" static, Sorry im new to coding..

avatar image Josh Naylor ♦♦ · Jul 09, 2014 at 10:54 AM 0
Share
 public static int click = 0;
avatar image RustyHook · Jul 09, 2014 at 10:55 AM 0
Share

Thankyou SO $$anonymous$$UCH, Technique.. You don't understand how long ive been trying to fix this, What do I do now to give you, rep points or something! :)!

avatar image Tehnique · Jul 09, 2014 at 11:03 AM 0
Share

Heh, it's no problem, mate, glad I could help! Remember: static values are shared by all instances, non-statics have different values for each instance.

avatar image Tehnique · Jul 09, 2014 at 11:11 AM 0
Share

Is your script named the same as the class inside? So "public class Score" should be inside a file named "Score".

Show more comments

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Code Not working 1 Answer

Modified Roll a Ball Tutorial,Modified Roll a Ball tutorial question 1 Answer

How can I instantiate more prefabs as the score increases? 2 Answers

How do I Instantiate a prefab to touch and still update a score? 1 Answer

Instantiate already connected players. 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