game(scripts): add CameraFollower and TriggerFunctionRemapper

This commit is contained in:
Mark Joshwel 2025-02-16 22:29:23 +08:00
parent 5c3b689de1
commit 6ed56e2e58
4 changed files with 69 additions and 0 deletions

View file

@ -0,0 +1,24 @@
/*
* Author: Mark
* Date: 16/2/25
* Description: follows the XR Camera's position
*/
using System;
using UnityEngine;
public class XRColliderFollow : MonoBehaviour
{
[SerializeField] private Transform xrCamera;
private void Awake()
{
if (xrCamera != null) return;
throw new Exception("Please assign the XR Camera to the XRColliderFollow script!");
}
private void Update()
{
transform.position = xrCamera.position;
}
}

View file

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 27b115b1b7297054cabb4ec1e403b751
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -0,0 +1,23 @@
/*
* Author: Mark
* Date: 16/2/25
* Description: allows changing what code is executed when a trigger is entered
*/
using System;
using UnityEngine;
public class TriggerFunctionRemapper : MonoBehaviour
{
private Action<Collider> _onTriggerEnter;
private void OnTriggerEnter(Collider other)
{
_onTriggerEnter?.Invoke(other);
}
public void Remap(Action<Collider> func)
{
_onTriggerEnter = func;
}
}

View file

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 396d8c6bf380c7241bc652343cbf11f6
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: