|
I would like to add a simple score counter to my code my issue is I have tried all other methods of doing this and it just doesn't seem to want to work . Can anyone help me? Here is the code I want to add the score counter to: using UnityEngine; using System.Collections; public class DamagableObject : MonoBehaviour { }
(comments are locked)
|
|
Given that you don't specify HOW you intend to actually create your score feedback, I can only tell you that you can easily do that in
for example with a very very simple
where score is your score variable of course, set and updated elsewhere, naturally. To acually hold the score information, you usually need to keep a 'game master' object in your scene, that basically has a function you call whenever score is earned. Additionally, a more versatile but slightly harder approach is to use what are called 'singletons', which correspond to static classes in c#. Those classes have project wide, one instance variables, that can be dereferenced from anywhere on the project. Supposing you have a static class like this:
in any of your code you can just write
and it'll work as intended. Thank you I will give that a shot and see what comes out from it
Jan 11 '12 at 03:29 PM
Matt 5
I tried this and it works for one enemy and I am trying to Update it but it is just not working. I've tried doing Scoring.m_score ++; but that just updates it all the time and I just want it to update when the death function is called again so I tried: Update() { if(Death()) { Scoring.m_score += 1; } } If I am doing something wrong can you or someone help me with this?
Jan 11 '12 at 05:41 PM
Matt 5
(comments are locked)
|
|
What I was looking for and sorry for not explaining it in more detail was the score to display based on the the destroy of the gameObject and increase by 10 as each enemy is destroyed. you usually add your notes as comments rather than replies, since these last ones from your part make the question harder to understand. I've updated my reply with more info on the subject.
Jan 11 '12 at 06:44 AM
roamcel
(comments are locked)
|
|
Need code formatting for this so I'm making it a new reply (note: UNTESTED CODE): Your it's the right approach but it's a bit flawed. What you need is a FUNCTION to call in your scorekeeping script. then, whenever you need to increase your score, from another class This code works amazing but now I want to apply a texture that the score will display on now I've tried GUI.DrawTexture(Rect 100, 25, 100, 30), "texture name"); but that keeps coming up with errors, I've also tried GUI.DrawTexture(new Rect(100, 25, 100, 30),Scoring.m_score.ToString(),"texture name"); as well as GUI.Label(new Rect(100, 25, 100, 30),Scoring.m_score.ToString(), "texture name");
Jan 25 '12 at 05:33 PM
Matt 5
(comments are locked)
|
