Türe öffnen und schließen sich per Button und das Licht kann man ebenfalls per Button an-aus schalten. Sound würde dafür fehlen.
This commit is contained in:
59
Assets/Scripts/Door/Door.cs
Normal file
59
Assets/Scripts/Door/Door.cs
Normal file
@@ -0,0 +1,59 @@
|
||||
using UnityEngine;
|
||||
|
||||
public class Door : MonoBehaviour
|
||||
{
|
||||
[SerializeField] private GameObject light;
|
||||
|
||||
[SerializeField] private Vector3 openPos;
|
||||
[SerializeField] private Vector3 closePos;
|
||||
|
||||
[SerializeField] private float doorSpeed;
|
||||
|
||||
public bool isOpen;
|
||||
public bool isOn;
|
||||
|
||||
// Start is called once before the first execution of Update after the MonoBehaviour is created
|
||||
void Start()
|
||||
{
|
||||
transform.position = openPos;
|
||||
isOpen = true;
|
||||
|
||||
ChangeLights();
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
if (isOpen) {
|
||||
if (transform.position != openPos) {
|
||||
// Damit sich die Tür smooth öffnen lässt.
|
||||
if (Vector3.Distance(transform.position, openPos) <= 0.5f) {
|
||||
transform.position = openPos;
|
||||
}
|
||||
else {
|
||||
transform.position = Vector3.Lerp(transform.position, openPos, doorSpeed * Time.deltaTime);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (transform.position != closePos) {
|
||||
// Damit sich die Tür smooth öffnen lässt.
|
||||
if (Vector3.Distance(transform.position, closePos) <= 0.5f) {
|
||||
transform.position = closePos;
|
||||
} else {
|
||||
transform.position = Vector3.Lerp(transform.position, closePos, doorSpeed * Time.deltaTime);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void ChangeLights() {
|
||||
isOn = !isOn;
|
||||
|
||||
if (isOn) {
|
||||
light.SetActive(true);
|
||||
}
|
||||
else {
|
||||
light.SetActive(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
2
Assets/Scripts/Door/Door.cs.meta
Normal file
2
Assets/Scripts/Door/Door.cs.meta
Normal file
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a009b121b39a02d4a8dddf11cbda97cc
|
||||
10
Assets/Scripts/Door/DoorController.cs
Normal file
10
Assets/Scripts/Door/DoorController.cs
Normal file
@@ -0,0 +1,10 @@
|
||||
using UnityEngine;
|
||||
|
||||
public class DoorController : MonoBehaviour
|
||||
{
|
||||
[SerializeField] private Door door;
|
||||
|
||||
private void OnMouseDown() {
|
||||
door.isOpen = !door.isOpen;
|
||||
}
|
||||
}
|
||||
2
Assets/Scripts/Door/DoorController.cs.meta
Normal file
2
Assets/Scripts/Door/DoorController.cs.meta
Normal file
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b48d47b843b1eb242981ed20cce0db89
|
||||
10
Assets/Scripts/Door/LightController.cs
Normal file
10
Assets/Scripts/Door/LightController.cs
Normal file
@@ -0,0 +1,10 @@
|
||||
using UnityEngine;
|
||||
|
||||
public class LightSystem : MonoBehaviour
|
||||
{
|
||||
[SerializeField] private Door door;
|
||||
|
||||
private void OnMouseDown() {
|
||||
door.ChangeLights();
|
||||
}
|
||||
}
|
||||
2
Assets/Scripts/Door/LightController.cs.meta
Normal file
2
Assets/Scripts/Door/LightController.cs.meta
Normal file
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0eef5257bc8558642b991b9857cf053f
|
||||
Reference in New Issue
Block a user