respawning

This commit is contained in:
2023-04-11 13:40:17 +02:00
parent fd44becec0
commit a0aaf5e87d
12 changed files with 586 additions and 164 deletions

View File

@@ -0,0 +1,17 @@
using EscapeRoomEngine.Engine.Runtime.Utilities;
using UnityEngine;
namespace Station46.Scripts
{
[RequireComponent(typeof(Collider))]
public class RespawnTrigger : MonoBehaviour
{
private void Awake()
{
if (!GetComponent<Collider>().isTrigger)
{
throw new WrongTypeException($"{this} must have a trigger collider.");
}
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 7a0c8567dfd74fefb6f5e90098ab7af3
timeCreated: 1683720477

View File

@@ -0,0 +1,44 @@
using EscapeRoomEngine.Engine.Runtime.Utilities;
using UnityEngine;
namespace Station46.Scripts
{
/// <summary>
/// An object that will be placed in its original position if it falls off the platform.
/// </summary>
[RequireComponent(typeof(Collider), typeof(Rigidbody))]
public class Respawning : MonoBehaviour
{
private Vector3 _spawnPosition;
private Quaternion _spawnRotation;
private Rigidbody _rigidbody;
private void Awake()
{
_rigidbody = GetComponent<Rigidbody>();
if (GetComponent<Collider>().isTrigger)
{
throw new WrongTypeException($"{this} must have a rigidbody collider.");
}
}
private void Start()
{
var t = transform;
_spawnPosition = t.position;
_spawnRotation = t.rotation;
}
private void OnTriggerEnter(Collider other)
{
var respawnTrigger = other.GetComponent<RespawnTrigger>();
if (respawnTrigger)
{
transform.SetPositionAndRotation(_spawnPosition, _spawnRotation);
_rigidbody.velocity = Vector3.zero;
_rigidbody.angularVelocity = Vector3.zero;
}
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 883312c0b43e43d4bd9b113d29da2ee2
timeCreated: 1683720386