V
V
vladniksin2020-12-18 23:30:31
Unity
vladniksin, 2020-12-18 23:30:31

Why does it swear at Play() in GetComponent() - Unity?

I'm trying to run an animation and Animation. The second day I'm scratching my head why so? (comment in code)

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

public class DetectClicks : MonoBehaviour
{
    public GameObject buttons, m_cube;
    public Text playText, gameName;
    private bool clicked;
    private void OnMouseDown()
    {
        if (!clicked)
        {
            clicked = true; //если еще не стартовали, то стартуем
            playText.gameObject.SetActive(false);//деактивируем 
            gameName.text = "0"; //обнуляем название игры
            buttons.GetComponent<ScrollObjects>().speed = -10;
            buttons.GetComponent<ScrollObjects>().checkPos = -180f;

            m_cube.GetComponent<Animation>().Play("GoToStart"); //тут ругается на Play
        }
    }
}


Error CS1061 'Animation' does not contain a 'Play' definition, and could not find an available extension method 'Play' that takes type 'Animation' as the first argument (perhaps a using directive or assembly reference is missing).

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
vladniksin, 2020-12-21
@vladniksin

Updated, rewritten, deleted, nothing has changed ...
I solved the issue through Animator.
m_cube.GetComponent<Animator>().Play("GoToStart");
The Animator itself had to be tweaked a bit...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question