Door Script not working

I have a door and a player and they both have box colliders that are triggers. Neither rotating or triggering an animation would work.
Here is my code:

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

public class DoorScript : MonoBehaviour
{
    public bool open = false;
    public float doorOpenAngle = 90f;
    public float doorCloseAngle = 0f;
    public float smooth = 2f;


    // Use this for initialization
    void Start()
    {
        open = true;
        Debug.Log(open);

    }

    private void OnTriggerEnter(Collider other)
    {
        if (other.CompareTag("Player"))
        {
            open = true;
        }
    }

    // Update is called once per frame
    void Update()
    {
        if (open == true)
        {
            Quaternion targetRotation = Quaternion.Euler(0, doorOpenAngle, 0);
            transform.localRotation = Quaternion.Slerp(transform.localRotation, targetRotation, smooth * Time.deltaTime);
        }

        else
        {
            Quaternion targetRotation2 = Quaternion.Euler(0, doorCloseAngle, 0);
            transform.localRotation = Quaternion.Slerp(transform.localRotation, targetRotation2, smooth * Time.deltaTime);
        }
    }

}

Do any of your GameObject have a Rigidbody attached? You can only trigger those events if one of them have a Rigidbody: source

1 Like