Welcome!

Welcome to our community forums, full of great people, ideas and excitement. Please register if you would like to take part.

This is extra text with a test link..

Register Now

Announcement

Collapse
No announcement yet.

Score Assistance

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Score Assistance

    I have the scorekeeper, and the scorekeeper script. do I attach it to the targets for the tin cup alley project?

  • #2
    It will be just like in Pachinko and Space Invaders. You can open those projects on a Mac or PC.

    You'll need to have a ScoreKeeper gameObject that has a ScoreKeeperScript on it.
    Each of the targets will need to have a script that probably has something like this in it:

    Code:
    public GameObject scoreKeeperGO;
    public int myValue;
    
    void OnCollisionEnter (collider other)
    {
         scoreKeepterGO.GetComponent<ScoreKeeperSciprt>().ChangeScore(myValue);
    }

    Comment


    • #3
      I did, but it's not changing the score, nor the highscore. what did I do wrong here?

      Comment


      • #4
        Hard to tell without seeing your project or scripts. Why don't you post your two scripts (ScoreKeeper and Target) and we can start from there. Be sure to put the "[code]" tags around it (it's the # sign button).

        Comment


        • #5
          using System.Collections;
          using System.Collections.Generic;
          using UnityEngine;

          public class TargetScript : MonoBehaviour
          {

          public int myValue;
          public GameObject Scorekeeper;

          private void OnCollisionEnter(Collision collision)
          {
          iTween.RotateTo(transform.parent.gameObject, new Vector3(90f, 0f, 0f), .5f);
          }

          IEnumerator StandUp()
          {
          float randomWaitTime;
          randomWaitTime = Random.Range(1f, 3f);

          yield return new WaitForSeconds(randomWaitTime);

          iTween.RotateTo(transform.parent.gameObject, new Vector3(0f, 0f, 0f), 2f);
          }

          void OnCollisionEnter(Collider Other)
          {
          Scorekeeper.GetComponent<ScoreKeeperScript>().Chan geScore(myValue);
          }
          }
          The first one is the Target script, here is the scorekeeper script:

          using System.Collections;
          using System.Collections.Generic;
          using UnityEngine;
          using UnityEngine.UI;

          public class ScoreKeeperScript : MonoBehaviour
          {
          public int score;
          public Text scoreUI;
          public void ChangeScore(int sentValue)
          {
          score = score + sentValue;
          GameObject.Find("ScoreUI").GetComponent<Text>().te xt = score.ToString();
          }
          }

          Comment


          • #6
            Please, please, please use the # button and then paste your code within the ["code"] and ["/code"] tabs. Really tough to read code this way.

            A few things:
            1. Your TargetScript has two OnCollisionEnter functions. It should have only one (with both your iTween and ScoreKeeper.GetComponent work in it).
            2. There are a few weird spaces in there "Chan geScore" not sure if that's just a copy/paste error or if thats really in your code. If it is you need to fix that.
            3. Make sure that on all your targets that you've actually changed the score from "0".

            Other than that, the code looks reasonable. When you play the game I'm betting that the console shows an error or two. What are those errors?

            Comment


            • #7
              for the second one, I didn't see any spacing errors. Also, do I need to set the score script on the targets too?

              Comment


              • #8
                The target script should be on each (and every) target. There should be only one ScoreKeeper script that should be on the gameObject in your scene that is the Scorekeeper.

                Comment


                • #9
                  I have the myValue thing set on the target script, and their calling to it, but the score on the screen remains unchanged. do I need to make that the child of the scorekeeper? or do I need to do something else?

                  Comment


                  • #10
                    Also, do I keep the score script as well? that one works fine, by the way.

                    Comment


                    • #11
                      how can I change the score on the targets? I set the myValue to what they needed to be.

                      Comment


                      • #12
                        Never Mind! I got it! now I just need to connect it to the game over screen and I'm set! how do I do that again? also, the high score thing too.

                        Comment


                        • #13
                          PlayerPrefs.

                          Comment


                          • #14
                            that was...playerprefs.getinfo...something like that?

                            Comment


                            • #15
                              and which code would I need to put it in in order to work properly?

                              Comment

                              Working...
                              X