respawning
This commit is contained in:
17
Assets/Station46/Scripts/RespawnTrigger.cs
Normal file
17
Assets/Station46/Scripts/RespawnTrigger.cs
Normal 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.");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
3
Assets/Station46/Scripts/RespawnTrigger.cs.meta
Normal file
3
Assets/Station46/Scripts/RespawnTrigger.cs.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7a0c8567dfd74fefb6f5e90098ab7af3
|
||||
timeCreated: 1683720477
|
||||
44
Assets/Station46/Scripts/Respawning.cs
Normal file
44
Assets/Station46/Scripts/Respawning.cs
Normal 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
3
Assets/Station46/Scripts/Respawning.cs.meta
Normal file
3
Assets/Station46/Scripts/Respawning.cs.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 883312c0b43e43d4bd9b113d29da2ee2
|
||||
timeCreated: 1683720386
|
||||
Reference in New Issue
Block a user