• 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 matt_sunley · Aug 29, 2015 at 03:24 AM · collisionscript.scorescore systemcounter

How do you add +1 to a score counter after a destroy script (C#)?

I need a script that adds 1 to my score when a destroy script is triggered. This is my destory script. using UnityEngine; using System.Collections;

public class DestroyScript : MonoBehaviour

 {
 public GameObject Explosion;

 void OnTriggerEnter (Collider Other)
 {
     if(Other.tag == "Player")
     {
         Instantiate (Explosion,transform.position, transform.rotation);
         Destroy(gameObject);
     }
 }

} strong text

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

Answer by SpaceManDan · Aug 29, 2015 at 03:49 AM

 public GameObject Explosion;
 private float score;

 void OnTriggerEnter (Collider Other)
 {
  if(Other.tag == "Player")
  {
      Instantiate (Explosion,transform.position, transform.rotation);
      score++;
      Destroy(gameObject);
  }

}

Comment
Add comment · Show 4 · 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 SpaceManDan · Aug 29, 2015 at 03:51 AM 0
Share

you can print the score by adding

 Debug.Log(score);
avatar image matt_sunley · Aug 29, 2015 at 04:47 AM 0
Share

Thank you! How do i make it update on the GUI?

avatar image SpaceManDan · Aug 29, 2015 at 05:12 AM 0
Share

Do you have a UI Text object already? Like, do you already have a working/existing UI or do you need to add one from scratch?

avatar image matt_sunley · Aug 29, 2015 at 06:40 AM 0
Share

I need to add one from scratch! cheers for the help

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

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

29 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

Related Questions

How can I keep a score counter of how many points the player has collected on the screen? 1 Answer

My character doesn't detect collisions or Hinge joint. 0 Answers

Score counter system 2nd script and ball a little problem 1 Answer

Anyway To Set A Specific Part Of Code To A Scene? 2 Answers

How can I make a scoretable in which players with the same puntuatio have the same rate? 1 Answer

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges