47 lines
1.4 KiB
C#
47 lines
1.4 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
public class LoopTrigger : MonoBehaviour
|
|
{
|
|
public LoopedRoom loopedRoom;
|
|
|
|
private void OnTriggerEnter(Collider col)
|
|
{
|
|
if (col.gameObject.tag == "Player" && loopedRoom.CanChangeLoop)
|
|
{
|
|
loopedRoom.PreviousRoomLoopID = loopedRoom.CurrentRoomLoopID;
|
|
StartCoroutine(CurrentRoomUpdate());
|
|
}
|
|
}
|
|
|
|
public void UpdateLoopID()
|
|
{
|
|
loopedRoom.CurrentRoomLoopID += 1;
|
|
}
|
|
|
|
IEnumerator CurrentRoomUpdate()
|
|
{
|
|
yield return new WaitForSeconds(0.1f);
|
|
loopedRoom.CurrentRoomLoopID += 1;
|
|
}
|
|
|
|
private void OnTriggerExit(Collider col)
|
|
{
|
|
if (col.gameObject.tag == "Player")
|
|
{
|
|
if (loopedRoom.CanChangeLoop)
|
|
{
|
|
loopedRoom.NextRoomLoopID = loopedRoom.CurrentRoomLoopID;
|
|
loopedRoom.NextRoomLoopID += 1;
|
|
//loopedRoom.CanChangeLoop = false;
|
|
loopedRoom.ChangeLoopedRoom = true;
|
|
}
|
|
loopedRoom._player.parent = loopedRoom._room[loopedRoom.CurrentRoomLoopID].transform; //Makes player child of the current room.
|
|
transform.position = loopedRoom.LoopTriggerTeleportPoint.position; //Teleports trigger to world Pos.
|
|
transform.rotation = loopedRoom.LoopTriggerTeleportPoint.rotation; //Matches trigger's rotation to the new transform.
|
|
}
|
|
}
|
|
|
|
}
|