Sensor based door open/close unity tutorial | Slide door using sensor in unity3d
ASSALAM o alaikum In this video we have shown how to open a door using slide on sensing if anything is near it
Code :
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class DoorManager : MonoBehaviour
{
public Transform player;
public float currentDistance, minimumDistance;
bool doorOpen;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
currentDistance = Vector3.Distance(player.position,transform.position);
if (currentDistance greater than sign =minimumDistance && !doorOpen)
{
doorOpen = true;
GetComponent less than sign Animator greater than sign ().Play("DoorOpen");
}
else if (currentDistance greater than signminimumDistance && doorOpen)
{
doorOpen = false;
GetComponent less than sign Animator greater than sign ().Play("DoorClose");
}
}
}
/*
/////////////////////////////////////////////////////////////////////////////////////////////
ASSALAM o alaikum
All codes and concepts and videos from this channel are non copyrighted and free to use because we believe that knowledge should be freely available for everyone
/////////////////////////////////////////////////////////////////////////////////////////////
*/