Collecting score and starting animation of item.

Hello my friends! I am trying to accomplish something really easy but i am experiencing some issues.
I created simple collecting script, that allows me on triggerEvents to collect spheres (for example) then update my score. This part was easy.But now, i am trying to link this with an object that is underground (for example big arch or something) and when i collect the full amount of items (eg. when i update my score) i need this arch or door to appear from underground with animation. (cuz there is the quest item i needed for example) It may be teleporting or appearing too.Not necessary to be underground. I created the animation, but now i donā€™t know how to link them together.I assume i must went back in collecting script and where i update my score, i need to check if score is == to score that need for trigger the animation.But then i donā€™t know what to do.
Many thanks in advance!!! <3

Thatā€™s awesome. Without seeing code, hard to say anything specific, but I know there are TONS of tutorials out there that do all of the above things, and once you understand the key steps in each phase, you can put them together however you like. I highly recommend Brackeyā€™s Tutorials. Heā€™s really good. But the Unity tutorials linked above under Learning are also good.

1 Like

Thank you very much for the fast reply! I have this very basic script for collecting items.Here is the script:

using Packages.Rider.Editor.UnitTesting;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SocialPlatforms.Impl;
public class SpherePoint : MonoBehaviour
{
  
    private void OnTriggerEnter(Collider fpsController)
    {
        if (fpsController.transform.name == "FPSController")
        {
            KeepScore.Score += 100;
            Debug.Log("Hit the ball");
            Destroy(gameObject);
        }
    }
}

I have a little script for scoreboard that keeps score -

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class KeepScore : MonoBehaviour
{
    public static int Score = 0;
    // Start is called before the first frame update
    void Start()
    {
      
    }
    // Update is called once per frame
    void Update()
    {
      
    }
    void OnGUI()
    {
        GUI.Box(new Rect(100, 100, 100, 100), Score.ToString ());
    }
}

Now iā€™ve created a basic cube that i put underground and animated it to go up. I made the cube to play the animation only once.Now when i play the game the animation activates and it goes up. Ok, i need now to make the cube stays ā€œidleā€ and when i collect x items, then to trigger the animation. I tried something like this -

public class TestAnimationScript : MonoBehaviour
{
    // Start is called before the first frame update

    string animationName = "Test";
    void Start()
    {
       
    }

    // Update is called once per frame
    void Update()
    {
        if (KeepScore.Score == 400)
        {
            GetComponent<Animation>().Play(animationName);

        }
   
}
}

but i get this error
MissingComponentException: There is no ā€˜Animationā€™ attached to the ā€œAnimationTestā€ game object, but a script is trying to access it.
You probably need to add a Animation to the game object ā€œAnimationTestā€. Or your script needs to check if the component is attached before using it.
UnityEngine.Animation.Play (System.String animation) (at <049be2afe36f487eb06ef49d51a0bab6>:0)
TestAnimationScript.Update () (at Assets/TestAnimationScript.cs:20)

Many thanks!!! <3

There is no possible way I can express this any clearer than the error text above does. That is literally what you must do to fix this. If you donā€™t know how to do that, work through some Unity animation / Mecanim / Animator tutorials.

1 Like

Thanks.I was using animation instead of animator.I changed GetComponent().Play(animationName) to Animator and it worked :slight_smile: