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 /
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.

Follow this Question

Answers Answers and Comments

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Multiple score counters instead of just one? 2 Answers

High score value remains constant in game over scene, even if player has scored higher. 1 Answer

Plz Help, Score/Kill counter and Enemy Movement 0 Answers

I want my score to reset back to 0 but keep my highscore saved 3 Answers

How to create a score manager script involving awarding points from multiple objects? 2 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