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 simpleone · May 12, 2011 at 02:02 PM · scorecounterkill

Kill Counter --> Score

Hey,I've been searching around a lot after a kill counter script for like 2 days now but I can't find anything that actually really works - I want my score to increase everytime I kill a zombie with like 5 points or something...

I know that I gotta have a script that tells my GUI text to change and another one to tell it when the zombie dies but I can't still get it to work... Anyone know an example I can look on or an answered question that works?

                                             / Thanks

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

2 Replies

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

Answer by Ejlersen · May 12, 2011 at 02:34 PM

You could add a script to your zombies, e.g.:

public class Zombie : MonoBehaviour { public int points = 1; // You can edit this in the inspector

 void OnDestroy()
 {
     PointCounter.points += points;
 }

}

The GUI script would then be:

public class PointCounter : MonoBehaviour { public GUISkin guiSkin = null; public static int points = 0;

 void OnGUI()
 {
     GUI.skin = guiSkin;
     GUI.Label(new Rect(0.0f, 0.0f, 128.0f, 32.0f), points.ToString());
     GUI.skin = null;
 }

}

So, whenever a zombie is destroyed it will add the points its worth to the pointer counter.

GUISKIN: Read the answer below...

Comment
Add comment · Show 11 · 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 simpleone · May 12, 2011 at 02:57 PM 0
Share

When I add them I just get alot of errors -

Insert a semicolon at the end.

Unexpected token: int.

avatar image Ejlersen · May 12, 2011 at 04:48 PM 0
Share

Hm, are you adding this to a javascript file?

avatar image GesterX · May 12, 2011 at 04:53 PM 0
Share

The above code is in C#

avatar image sp00ks · May 12, 2011 at 05:08 PM 0
Share

by looking at this code it looks like points will always be 0, you aren't increasing by anything...

avatar image Ejlersen · May 12, 2011 at 05:42 PM 0
Share

GesterX: Yes, thats why I'm asking if he is adding it to a JavaScript file :)

Show more comments
avatar image
1
Best Answer

Answer by Ejlersen · May 12, 2011 at 08:17 PM

Just going to create a new answer for the comment:

... but how can I add a font or a texture to it? ...

You can use a GUISkin for that. You create the GUISkin in Unity in Project Hierarchy, then in the GUISkin you can choose label. In there you can set a font, size, and so on.

You use the GUISkin in the code by adding: GUI.skin = mySkin; in OnGUI() just before the label. You can then add the GUISkin by creating a public variable in the top of PointCounter with points. Then you can drag the GUISkin on to the GUISkin variable in the inspector.

Comment
Add comment · Show 2 · 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 simpleone · May 12, 2011 at 09:47 PM 0
Share

Can edit your script above it? I added what you told me, nothing happened - I probably wrote wrong ...

avatar image Ejlersen · May 12, 2011 at 10:09 PM 0
Share

Done. Remember to assign the GUIskin in the inspector.

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

1 Person is following this question.

avatar image

Related Questions

How to make a Kill Counter 1 Answer

How to "Increase score with Y axis"? 1 Answer

Score display error 1 Answer

Trying to get score counter... 2 Answers

Gun Script not working help please 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