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:
[ Ссылка ]
Try out my games:
[ Ссылка ]
Forgehub:
[ Ссылка ]
Subscribe to my Second Channel:
[ Ссылка ]
Join my Discord:
[ Ссылка ]
Facebook Page:
[ Ссылка ]
Follow me on Instagram:
[ Ссылка ]
Ещё видео!