finished portal fundimentals
This commit is contained in:
34
Assets/_PROJECT/Components/Portals2/Space enter Collider.cs
Normal file
34
Assets/_PROJECT/Components/Portals2/Space enter Collider.cs
Normal file
@@ -0,0 +1,34 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class SpaceEnterCollider : MonoBehaviour
|
||||
{
|
||||
private void OnTriggerEnter(Collider other)
|
||||
{
|
||||
GravityHandler playerGravity = other.GetComponent<GravityHandler>();
|
||||
if (playerGravity != null)
|
||||
{
|
||||
playerGravity.isInSpace = true;
|
||||
}
|
||||
Debug.Log(other + " entered space.");
|
||||
}
|
||||
|
||||
private void OnTriggerExit(Collider other)
|
||||
{
|
||||
GravityHandler playerGravity = other.GetComponent<GravityHandler>();
|
||||
if (playerGravity != null)
|
||||
{
|
||||
StartCoroutine(DelayExit(playerGravity));
|
||||
playerGravity.AdjustGravity(new Quaternion()); // Set Gravity back to default
|
||||
}
|
||||
Debug.Log(other + " left space.");
|
||||
}
|
||||
|
||||
private IEnumerator DelayExit(GravityHandler playerGravity)
|
||||
{
|
||||
yield return new WaitForSeconds(1f); // Wait for 1 second
|
||||
playerGravity.isInSpace = false;
|
||||
Debug.Log("Default gravity restored after 1 second.");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user