How to Make Doors in Unity - Unity C# Tutorial

How to Make Doors in Unity - Unity C# Tutorial

Omogonix

8 месяцев назад

3,275 Просмотров

Ссылки и html тэги не поддерживаются


Комментарии:

@Omogonix
@Omogonix - 03.11.2023 08:55

I've made a few door tutorials in the past before, but I always like to improve upon the methods I teach in my videos, thus why I'm making another door tutorial. The scripts I make in this video are a lot cleaner in my opinion and the main door script in particular can be used for opening/closing doors, wardrobes, closets, drawers, cupboards, etc.

Scripts:

Player Raycast script:

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

public class playerRaycast : MonoBehaviour
{
public GameObject crosshair;
public float interactionDistance;
public LayerMask layers;

void Update()
{
RaycastHit hit;
if(Physics.Raycast(transform.position, transform.forward, out hit, interactionDistance, layers))
{
if (hit.collider.gameObject.GetComponent<door>())
{
crosshair.SetActive(true);
if (Input.GetKeyDown(KeyCode.E))
{
hit.collider.gameObject.GetComponent<door>().openClose();
}
}
else
{
crosshair.SetActive(false);
}
}
else
{
crosshair.SetActive(false);
}
}
}

Door script:

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

public class door : MonoBehaviour
{
bool toggle;
public Animator anim;

public void openClose()
{
toggle = !toggle;
if(toggle == false)
{
anim.ResetTrigger("open");
anim.SetTrigger("close");
}
if (toggle == true)
{
anim.ResetTrigger("close");
anim.SetTrigger("open");
}
}
}

Ответить
@OLUVUH
@OLUVUH - 09.05.2024 03:02

this actually worked unlike the other tutorial you have

Ответить
@someguy9163
@someguy9163 - 06.05.2024 15:15

Nice

Ответить
@user-op2yz6my2m
@user-op2yz6my2m - 08.04.2024 15:59

[[[[[ PAY REAL ATTENTION TO THIS: THE "KEY" TO CREATE MULTIPLE DOORS WITH THE SAME ANIMATOR AND THE SAME SCRIPT IS IN MIN 6, the hierarchy of the game objects of the door]]] This is a very good tutorial!

Ответить
@Tchoupipo
@Tchoupipo - 24.03.2024 23:14

Why it does not work ? I did the code, placement and animation perfectly.

Ответить
@Glidching
@Glidching - 22.03.2024 00:11

Thank you so much works perfectly

Ответить
@Bloxi99
@Bloxi99 - 14.01.2024 11:56

To see the crosshair you almost have to walk in the door. Could you help me with that?

Ответить
@igussin
@igussin - 07.01.2024 17:20

thank you so much bro! This really helped!

Ответить
@mrdonut4537
@mrdonut4537 - 24.11.2023 00:59

tutorial on how to add open and close sound to the door please?

Ответить
@Colton_studios
@Colton_studios - 07.11.2023 03:37

Does the this game is for you series actually steal your date or is that just to scare people.

Ответить
@ITsAceplayez
@ITsAceplayez - 06.11.2023 15:37

Can you please show me how to make a interactable laptop in unity. I would appreciate is allot.

Ответить
@kennethmedel660
@kennethmedel660 - 05.11.2023 15:51

Can you create tutorial for objectives that player must do. if the player pressed 'Tab' all the objectives will be shown and when the player do that certain task, it will disappear. Thank you so much

Ответить
@kennethmedel660
@kennethmedel660 - 05.11.2023 15:51

Can you create tutorial for objectives that player must do. if the player pressed 'Tab' all the objectives will be shown and when the player do that certain task, it will disappear. Thank you so much

Ответить
@Colton_studios
@Colton_studios - 05.11.2023 09:00

Will there ever be a foreboding tales 2? It’s one of my favorite games made by you

Ответить
@eazyboyrade
@eazyboyrade - 04.11.2023 17:21

Protect this guy at all cost

Ответить
@kingiwakes_official
@kingiwakes_official - 04.11.2023 13:10

Can you do a tutorial how to do this cool thing in My Friendly Neighborhood. When you open the door. It plays an animation of you entering the room then loads a diffrent scene... If it's possible.

Ответить
@adi2k88
@adi2k88 - 04.11.2023 04:29

Would be useful if VS were in dark mode and abit zoomed.

Ответить
@Colton_studios
@Colton_studios - 04.11.2023 02:03

Yo what was the first game you made and published

Ответить
@Colton_studios
@Colton_studios - 04.11.2023 00:24

I’m just saying but what if in the next this game is for you installment the bunny takes over the players phone and locks them in there house.

Ответить
@Colton_studios
@Colton_studios - 03.11.2023 18:27

This is a great tutorial

Ответить
@SAN_GAMES_OFFICIAL
@SAN_GAMES_OFFICIAL - 03.11.2023 11:03

How much you earn bro please 🥺

Ответить
@mrsteve6986
@mrsteve6986 - 03.11.2023 10:34

Ty now ik how to do it

Ответить