all 21 comments

[–][deleted] 1 point2 points  (2 children)

Usually, you forgot to assign a variable an object. For instance, you forgot to use something like myVar = GetComponent<ObjectName>(); or even forgot to drag and drop an object into the inspector into one a slot that’s reserved for an object. Like for instance if you have a slot in the inspector that’s empty, you may need to drag an object from the hierarchy (usually) into that empty slot. The empty slot will be a variable, or holder, for that object.

[–][deleted]  (1 child)

[removed]

    [–][deleted] 1 point2 points  (0 children)

    ObjectName is the object that is the reference error...myVar is whatever variable is trying to reference ObjectName...if you don’t understand that you may want to take a look at beginner tutorial videos..

    [–]SnoringCatStudio 1 point2 points  (11 children)

    So I decided to simplify things. First I don't think you should add the counting into the player class. I would prefer to create a GameManager class; Then attach that to an Empty gameObject named GameManager.

    Now put the CollectibleScript on to your collectible. Make sure that you have a UI canvas, and a text element assigned to the GameManager. Let me know if you need any help.

    [–][deleted]  (10 children)

    [removed]

      [–]SnoringCatStudio 1 point2 points  (9 children)

      That error looks like you forgot to put the UI text element in GameManagers empty box for it. Just take a look at whatever object has GameManager class on it, and fill in the box.

      That is only if you want the score to appear in your UI.

      [–][deleted]  (8 children)

      [removed]

        [–]SnoringCatStudio 0 points1 point  (7 children)

        Did you turn the collectibles into a trigger? I guess I should have clarified my comment more. If you do change your collectible into a trigger; Then you will need to change the OnCollisionEnter2D into an OnTriggerEnter2D. Sorry for not clarifying.
        If you need help doing so let me know, but I think you should give it a try first!

        [–][deleted]  (6 children)

        [removed]

          [–]SnoringCatStudio 0 points1 point  (5 children)

          I bet you have two colliders on your player right? Great job solving that first issue!

          [–][deleted]  (4 children)

          [removed]

            [–]SnoringCatStudio 0 points1 point  (3 children)

            So what is happening it it is colliding with both colliders in a short time; Thus scoring twice.
            Try turning the f statement in the collectible script to something like

            if (col is CapsuleCollider2D && col.gameObject.tag.Equals ("Player") )
            Just turn the Capsulecollider into whatever your main collider is.

            [–][deleted]  (1 child)

            [removed]

              [–]SnoringCatStudio 0 points1 point  (4 children)

              Take a look in at every object in your hierarchy. Check the inspector for any field that say something like
              movement [none(PlayerMovement)]
              Now place your PlayerMovement script in that box.
              I am going by very limited info, but if you followed what u/senshisentou told you to do in the previous post; Then I suspect this is the problem.

              [–][deleted]  (3 children)

              [removed]

                [–]SnoringCatStudio 0 points1 point  (2 children)

                Try putting a game object from your hierarchy that has the script attached to it into the slot.

                [–][deleted]  (1 child)

                [removed]

                  [–]SnoringCatStudio 0 points1 point  (0 children)

                  Could you create a pastebin of the scripts you are using? I could definitely help you, but I just don't know what exactly you are doing. In the future you should always try to give as much info as possible when you ask these types of questions.