CALLING CHOICE DONE

This commit is contained in:
immaunicorn107 2025-02-14 15:38:52 +08:00
parent dbc7e66ba1
commit b1a1c80107
6 changed files with 584 additions and 7271 deletions

BIN
Game/.DS_Store vendored

Binary file not shown.

BIN
Game/Assets/.DS_Store vendored Normal file

Binary file not shown.

File diff suppressed because one or more lines are too long

View file

@ -1,13 +1,12 @@
using UnityEngine; using UnityEngine;
using UnityEngine.XR.Interaction.Toolkit; using UnityEngine.XR.Interaction.Toolkit;
using UnityEngine.SceneManagement; using UnityEngine.SceneManagement;
using UnityEngine.XR.Interaction.Toolkit.Interactors;
public class PhoneInteraction : MonoBehaviour public class PhoneInteraction : MonoBehaviour
{ {
public AudioClip phoneCallAudio; // Assign in Inspector public AudioClip phoneCallAudio; // Assign in Inspector
public GameObject choiceUI; // Assign your UI Panel in Inspector public GameObject choiceUI; // Assign your UI Panel in Inspector
public Transform attachTransform; // Drag XR Controller's Attach Transform here
private AudioSource audioSource; private AudioSource audioSource;
private bool phonePickedUp = false; private bool phonePickedUp = false;
@ -15,16 +14,43 @@ public class PhoneInteraction : MonoBehaviour
void Start() void Start()
{ {
audioSource = GetComponent<AudioSource>() ?? gameObject.AddComponent<AudioSource>(); // Ensure AudioSource is available
if (!TryGetComponent(out audioSource))
{
audioSource = gameObject.AddComponent<AudioSource>();
}
if (phoneCallAudio != null)
{
audioSource.clip = phoneCallAudio; audioSource.clip = phoneCallAudio;
}
choiceUI.SetActive(false); // Hide UI initially choiceUI.SetActive(false); // Hide UI initially
} }
void Update() // Public method to be used in XR Grab Interactable's On Select Entered event
public void PickUpPhone()
{
if (!phonePickedUp)
{
phonePickedUp = true;
Debug.Log("Phone Picked Up! Showing UI.");
choiceUI.SetActive(true); // Show UI panel
// Ensure phone attaches properly
if (attachTransform != null)
{
transform.position = attachTransform.position;
transform.rotation = attachTransform.rotation;
}
}
}
private void Update()
{ {
if (phonePickedUp && !choiceMade) if (phonePickedUp && !choiceMade)
{ {
if (Input.GetKeyDown(KeyCode.G)) if (Input.GetKeyDown(KeyCode.A))
{ {
AnswerCall(); AnswerCall();
} }
@ -35,29 +61,20 @@ public class PhoneInteraction : MonoBehaviour
} }
} }
public void PickUpPhone() private void AnswerCall()
{
if (!phonePickedUp)
{
phonePickedUp = true;
Debug.Log("Phone Picked Up! UI Appears.");
choiceUI.SetActive(true); // Show UI when picked up
}
}
void AnswerCall()
{ {
choiceMade = true; choiceMade = true;
Debug.Log("Phone Answered! Playing Audio..."); Debug.Log("Phone Answered! Loading GoodEnding...");
audioSource.Play(); choiceUI.SetActive(false);
choiceUI.SetActive(false); // Hide UI after choice
SceneManager.LoadScene("GoodEnding"); SceneManager.LoadScene("GoodEnding");
} }
void DeclineCall() private void DeclineCall()
{ {
choiceMade = true; choiceMade = true;
Debug.Log("Call Declined! Loading 'House' scene..."); Debug.Log("Call Declined! Loading BadEnding...");
choiceUI.SetActive(false);
SceneManager.LoadScene("BadEnding"); SceneManager.LoadScene("BadEnding");
} }
} }

Binary file not shown.

View file

@ -1,8 +0,0 @@
fileFormatVersion: 2
guid: dab25067a2d1bfb4284476dba6b9ae8d
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 15600000
userData:
assetBundleName:
assetBundleVariant: