S
S
SpeedM2019-07-22 18:43:22
Game development
SpeedM, 2019-07-22 18:43:22

How to stop an animation script in Unity?

Please help me figure out why the animation script (OlavAnimation) cannot be stopped when the game is started (clicked).

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

public class KillMe : MonoBehaviour
{
    private OlavAnimation Olav;
    // Start is called before the first frame update
    void Start()
    {
        Olav = GetComponent <OlavAnimation>();
    }

    // Update is called once per frame
    void Update()
    {
        if (Input.GetMouseButtonDown(0));
          Olav.enabled = false;

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Mikhail Filonenko, 2019-07-24
@kombain32

1. Is there an EventSystem on the stage in which this script is executed? Otherwise, your clicks are simply not read
2. Tried to debug (can you run a debugger?)? Does all code work?
3. Is OlavAnimation definitely present on the same object as the KillMe script? Again, turn on the debugger and see if the GetComponent<> function finds an OlavAnimation type component. (attach a screenshot of the inspector with this object to the question)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question