- Home /
 
creating score point for 3 objects
Hi, i'm doing a game which the player collect money 5,10,20 and each one have different score, i wrote the code but the errors don't show up and the score doesn't change .. please can anyone help me! i using C#
 private int Money5=0;
      private int Money10=0;
      private int Money20=0;
      private float timeleft=60;
      private int Scores=0;
      
      // Use this for initialization
      void Start () {
      
      }
      
      // Update is called once per frame
      void FixedUpdate () {
             timeleft = timeleft - Time.deltaTime;
      Scores = Money5 + Money10 + Money20;
          
      }
      
      // we must put a tick next to the trigger in the unity of the prefab
      void OnTriggerEnter(Collider other)
      {
          // the name pickUp should be the same in the unity of the prefab in the tag
          if (other.gameObject.tag == "money5") {
              other.gameObject.SetActive(false);
              Scores = 5 + Scores; // to make the score increasing by 5
              Destroy (other.gameObject);
          }
          if (other.gameObject.tag == "money10") {
              other.gameObject.SetActive(false);
              Scores = 10 + Scores; // to make the score increasing by 10
              Destroy (other.gameObject);
          }
          if (other.gameObject.tag == "money20") {
              other.gameObject.SetActive(false);
              Scores = 20 + Scores; // to make the score increasing by 20
              Destroy (other.gameObject);
          }
          
 void OnGUI() {
             
             string Scors = Scores.ToString ();
         GUI.Box (new Rect (190, 10, 70, 50), "Scores");
         GUI.Label (new Rect (190, 30, 150, 20),Scors);
         }
          
      }
 
              Answer by SkaredCreations · Dec 18, 2014 at 10:37 PM
You have a logic error: in FixedUpdate you're constantly resetting Scores to 0 (since you never assign Money5, Money10 and Money20 they remain at 0 like you initialized in the first lines of this script). Just remove the line 15 and you should be fine.
Your answer
 
             Follow this Question
Related Questions
I need help making a score system for a First Person Controller 1 Answer
How do you create a "collect" objection that corresponds with the enemy behavior in C#? 1 Answer
How do I make a score script based on the time the player is alive? 1 Answer
After I initially add score it keeps adding. 2 Answers
rotate the object based on the two-point 2 Answers