How to Make a Basic First Person Horror Game in Unity (Part 5) - Unity C# Tutorial 2022
This is part 5 to my 'How to Make a Basic First Person Horror Game in Unity' tutorial series.
#Unity #Unity3D #GameDevelopment
Be sure to like, comment, and subscribe if you want part 6 or just more Unity tutorials or videos from me in general. 👍
Door Script:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Door : MonoBehaviour
{
public GameObject door_closed, door_opened, intText, lockedtext;
public AudioSource open, close;
public bool opened, locked;
public static bool keyfound;
void Start(){
keyfound = false;
}
void OnTriggerStay(Collider other){
if(other.CompareTag("MainCamera")){
if(opened == false){
if(locked == false){
intText.SetActive(true);
if(Input.GetKeyDown(KeyCode.E)){
door_closed.SetActive(false);
door_opened.SetActive(true);
intText.SetActive(false);
StartCoroutine(repeat());
opened = true;
}
}
if(locked == true){
lockedtext.SetActive(true);
}
}
}
}
void OnTriggerExit(Collider other){
if(other.CompareTag("MainCamera")){
intText.SetActive(false);
lockedtext.SetActive(false);
}
}
IEnumerator repeat(){
yield return new WaitForSeconds(4.0f);
opened = false;
door_closed.SetActive(true);
door_opened.SetActive(false);
close.Play();
}
void Update(){
if(keyfound == true){
locked = false;
}
}
}
Watch the first part here:
https://youtu.be/g2cEOHzMDBc
Watch the second part here:
https://youtu.be/YeV_7xKbFKA
Watch the third part here:
https://youtu.be/Z1PV5K_ueWM
Watch the fourth part here:
https://youtu.be/Yhyn6qUtITk
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/