Compare commits
2 commits
c821722b96
...
cc493c7924
Author | SHA1 | Date | |
---|---|---|---|
cc493c7924 | |||
ddef973b3e |
3 changed files with 77 additions and 0 deletions
45
Game/Assets/Scripts/RubbishBinSocket.cs
Normal file
45
Game/Assets/Scripts/RubbishBinSocket.cs
Normal file
|
@ -0,0 +1,45 @@
|
|||
/*
|
||||
* Author: Isaac
|
||||
* Date: 7/2/25
|
||||
* Description: Script to handle the interaction between the rubbish bin and the trash objects
|
||||
*/
|
||||
|
||||
using UnityEngine;
|
||||
using UnityEngine.XR.Interaction.Toolkit;
|
||||
using UnityEngine.XR.Interaction.Toolkit.Interactables;
|
||||
using UnityEngine.XR.Interaction.Toolkit.Interactors;
|
||||
|
||||
public class RubbishBinSocket : MonoBehaviour
|
||||
{
|
||||
private XRSocketInteractor _socket;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
_socket = GetComponent<XRSocketInteractor>();
|
||||
|
||||
if (_socket == null)
|
||||
{
|
||||
Debug.LogError("XRSocketInteractor component is missing from the rubbish bin!");
|
||||
return;
|
||||
}
|
||||
|
||||
_socket.selectEntered.AddListener(OnTrashPlaced);
|
||||
}
|
||||
|
||||
private void OnDestroy()
|
||||
{
|
||||
if (_socket != null) _socket.selectEntered.RemoveListener(OnTrashPlaced);
|
||||
}
|
||||
|
||||
private void OnTrashPlaced(SelectEnterEventArgs args)
|
||||
{
|
||||
var trash = (XRBaseInteractable)args.interactableObject;
|
||||
|
||||
if (trash == null) return;
|
||||
Debug.Log($"{trash.gameObject.name} was placed in the rubbish bin and destroyed.");
|
||||
Destroy(trash.gameObject);
|
||||
|
||||
// Add haptic feedback if using a VR controller
|
||||
if (args.interactorObject is XRBaseInputInteractor controller) controller.SendHapticImpulse(0.7f, 0.2f);
|
||||
}
|
||||
}
|
11
Game/Assets/Scripts/RubbishBinSocket.cs.meta
Normal file
11
Game/Assets/Scripts/RubbishBinSocket.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: b3d5a817584b84da0a08814feb482587
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
21
Game/Assets/Scripts/SceneLoader.cs
Normal file
21
Game/Assets/Scripts/SceneLoader.cs
Normal file
|
@ -0,0 +1,21 @@
|
|||
/*
|
||||
* Author: Wai Lam
|
||||
* Date: 7/2/25
|
||||
* Description: Loading scene from start to game
|
||||
*/
|
||||
|
||||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
|
||||
public class SceneLoader : MonoBehaviour
|
||||
{
|
||||
public string sceneName; // Name of the scene to load
|
||||
|
||||
public void LoadScene()
|
||||
{
|
||||
if (!string.IsNullOrEmpty(sceneName))
|
||||
SceneManager.LoadScene(sceneName);
|
||||
else
|
||||
Debug.LogWarning("Scene name is not assigned!");
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue