Search Unity

[Solved] Door animation open/close if the player is near to the door

Discussion in 'Animation' started by qxeCompany, Sep 13, 2021.

  1. qxeCompany


    Nov 9, 2020
    I'm following a YouTube tutorial about making a door open and close when ever you get near to it and so I completed everything . the animations and the code its all the same and there is no errors but the problem is the door are not moving but the trigger are moving ( when ever the player collide with the trigger the door animation should start and the door go to the right side I have already made that animation . and after the player are outside the trigger the door are back ( the close animation start) )

    i used this asset
    3D Free Modular Kit | 3D Environments | Unity Asset Store

    any way here in this video i showed everything i did

    as you can see in the video at the first the cube that meant to be DoorTrigger is the only thing that moving and not the door its the same thing if i made the door prefab as child of the DoorTrigger because for no reasone the animation are working only for the cube and not the door and just to let you know . when i created the animation i was animating the door with no problem>

    Here is another video And in this one I showed the animations are working Fine No problem

    Here is my code [I don't think there is a problem]
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    5. public class DoorController : MonoBehaviour
    6. {
    7.     Animator _doorAnim;
    9.     private void OnTriggerEnter(Collider other)
    10.     {
    11.         _doorAnim.SetBool("isOpening", true);
    12.     }
    14.     private void OnTriggerExit(Collider other)
    15.     {
    16.         _doorAnim.SetBool("isOpening", false);
    17.     }
    19.     // Start is called before the first frame update
    20.     void Start()
    21.     {
    22.         _doorAnim = this.transform.parent.GetComponent<Animator>();
    24.     }
    26.     // Update is called once per frame
    27.     void Update()
    28.     {
    30.     }
    31. }

    if you need more info please tell me what you need and I will give please put in mind that I'm a beginner in unity but I have a good programming background with C#
    And this is the video I'm following

    the thing that was moving is the static so i disabled it and its now good and work
    Last edited: Sep 14, 2021