Unity 3D Open and Close Door Script C#

Опубликовано: 19 Март 2026
на канале: Blender Cubed
1,785
20

In this tutorial I add a C# script to open and close the door when an FPS player enters a trigger.

I have added the code below but it wouldn't let me put the word Animator in angle brackets, these are the brackets above , and .

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


public class doorscript : MonoBehaviour {
private Animator _animator;

// Use this for initialization
void Start () {
_animator = GetComponent Animator(); //put Animator in angle brackets

}

void OnTriggerEnter(Collider other)
{
if (other.tag == "player")
{
_animator.SetBool("open", true);
}
}

void OnTriggerExit(Collider other)
{
if (other.tag == "player")
{
_animator.SetBool("open", false);
}
}