How to Make Basic Doors in Unity - Unity C# Tutorial
In this Unity tutorial, I teach you guys how to make basic doors in Unity 3D. We'll also be making use of the C# programming language for this tutorial.
#Unity #Unity3D #GameDevelopment
For more Unity C# tutorials - be sure to like, comment, and subscribe for more! 👍
Script:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Door : MonoBehaviour
{
public GameObject doorClosed, doorOpened, intIcon;
public float openTime;
void OnTriggerStay(Collider other){
if(other.CompareTag("MainCamera")){
intIcon.SetActive(true);
if(Input.GetKeyDown(KeyCode.E)){
intIcon.SetActive(false);
doorClosed.SetActive(false);
doorOpened.SetActive(true);
StartCoroutine(closeDoor());
}
}
}
IEnumerator closeDoor(){
yield return new WaitForSeconds(openTime);
doorOpened.SetActive(false);
doorClosed.SetActive(true);
}
void OnTriggerExit(Collider other){
if(other.CompareTag("MainCamera")){
intIcon.SetActive(false);
}
}
}
Follow me on Twitter:
https://twitter.com/omogonix
Try out my games:
https://omogonixlachlan.itch.io
Forgehub:
https://www.forgehub.com/members/omogonix.87700/
Subscribe to my Second Channel:
https://www.youtube.com/channel/UCkylkvUtpvbHfafGfIdMLBQ/featured
Join my Discord:
https://discord.gg/a88vmGD
Facebook Page:
https://www.facebook.com/Omogonix/
Follow me on Instagram:
https://www.instagram.com/uwugonixhalo/