Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.

Animation is not working

Discussion in 'Windows' started by mielnik314, Jun 3, 2022.

  1. mielnik314

    mielnik314

    Joined:
    Jun 3, 2022
    Posts:
    3
    Hello. I would like to make animations of opening the door which closes by itself after 3 seconds. I do everything 1: 1 like from the tutorial, but the animation still doesn't work. What could be the problem? This is my code.
    upload_2022-6-4_0-17-59.png
    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    public class LoopManager : MonoBehaviour
    {
    public Animator doorsAnim;
    [SerializeField] float sec;
    [SerializeField] bool canMove;
    public Movement move;
    public MouseLook mouse;
    public FlashLight flash;
    public int whichLoop;
    public GameObject startLoopTrigger;
    // Start is called before the first frame update
    void Start()
    {
    canMove = false;
    whichLoop = 0;
    }
    // Update is called once per frame
    void Update()
    {
    if(canMove)
    {
    sec += 1 * Time.deltaTime;
    }
    if(!canMove)
    {
    sec = 0;
    move.speed = 2f;
    mouse.sens = 1000f;

    }
    if(sec > 0)
    {
    move.speed = 0f;
    mouse.sens = 0f;
    transform.Translate(0, 0, 0.8f * Time.deltaTime);

    }
    if(sec >= 3)
    {
    canMove = false;
    }

    }
    public void OnTriggerEnter(Collider other)
    {
    if(other.CompareTag("loop"))
    {
    transform.position = new Vector3(-6.2f, 0.879f, 5.174f);
    mouse.MouseX = 90f;
    doorsAnim.SetInteger("loop", 1);
    canMove = true;
    whichLoop += 1;
    }
    }
    public void OnTriggerExit(Collider other)
    {
    if(other.CompareTag("loop"))
    {
    doorsAnim.SetInteger("loop", 0);
    }
    }
    }