• 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 Sottnik · Mar 28, 2017 at 07:18 AM · scripting problemscore

Scoring points problem

Hello everyone, I am new in Unity and I need your help. I am doing game almost same as on Image but I have got there 4 pick up objects with different shapes.alt text I dont know how to count score,under every side of square I have placed empty game object with script attached.

  void OnTriggerEnter2D(Collider2D other)
     {
 
         if (other.gameObject.CompareTag("Triangel"))
         {
             Destroy(other.gameObject);
             clipAudio.Play();
             count = count + 1;
 
 
         }
 
     }

But when I picked up different object score has restarted. Here is my ScoreController which doesnt work. I have no idea what to do next. Please help me I will appreciate it.

public Text countText; public int count; public int Count1; public int Count2; public int Count3; public int Count4;

 private void Start()
 {
     
    

     Count1= GameObject.Find("Triangels").GetComponent<TriangelsPickUp>().count1;
     Count2 = GameObject.Find("Squares").GetComponent<SquaresPickUp>().count2;
     Count3 = GameObject.Find("Circles").GetComponent<CirclesPickUp>().count3;
     Count4 = GameObject.Find("Diamonts").GetComponent<DiamontsPickUp>().count4;
     SetCountText();
     count = 0;
     

 }



 private void Update()
 {
     count = Count1+Count2+Count3+Count4;
     SetCountText();       
 }
 void SetCountText()
 {
   countText.text = "Score: " + count.ToString();
 }
 


game.png (11.9 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

1 Reply

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

Answer by shadowpuppet · Mar 28, 2017 at 07:21 PM

I'd like to help as I had the same issue a while back. But my game is 3D not 2D and I know nothing about 2d. My score is text on the HUD Canvas with a "score manager "script attached to it. this is the script I use on the scoretext

 using UnityEngine;
 using UnityEngine.UI;
 using System.Collections;
 
 public class ScoreManager : MonoBehaviour
 {
     public static int score = 00; 

     void Awake ()
     {
     
         text = GetComponent <Text> ();
         
     }
     

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


and to add to the score on another gameObject

void OnTriggerEnter (Collider other) {

     if(other.tag == "Grenade")
             
         ScoreManager.score+=100;
 }

}

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 Sottnik · Mar 28, 2017 at 08:23 PM 0
Share

Thanks a lot. It has solved my problem.I really appreciate it.@shadowpuppet

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

My score script doesn't seem to work properly, score is not added properly 0 Answers

Central score counter for 3 score generating buttons 1 Answer

INCREASE SCORE MORE AND MORE? 1 Answer

Score counter breaking after adding points 2 Answers

Ending a game with Points 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