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.XR.Interaction.Toolkit;
using UnityEngine.SceneManagement;
using UnityEngine.XR.Interaction.Toolkit.Interactors;
public class PhoneInteraction : MonoBehaviour
{
public AudioClip phoneCallAudio; // Assign 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 bool phonePickedUp = false;
@ -15,16 +14,43 @@ public class PhoneInteraction : MonoBehaviour
void Start()
{
audioSource = GetComponent<AudioSource>() ?? gameObject.AddComponent<AudioSource>();
audioSource.clip = phoneCallAudio;
// Ensure AudioSource is available
if (!TryGetComponent(out audioSource))
{
audioSource = gameObject.AddComponent<AudioSource>();
}
if (phoneCallAudio != null)
{
audioSource.clip = phoneCallAudio;
}
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 (Input.GetKeyDown(KeyCode.G))
if (Input.GetKeyDown(KeyCode.A))
{
AnswerCall();
}
@ -35,29 +61,20 @@ public class PhoneInteraction : MonoBehaviour
}
}
public void PickUpPhone()
{
if (!phonePickedUp)
{
phonePickedUp = true;
Debug.Log("Phone Picked Up! UI Appears.");
choiceUI.SetActive(true); // Show UI when picked up
}
}
void AnswerCall()
private void AnswerCall()
{
choiceMade = true;
Debug.Log("Phone Answered! Playing Audio...");
audioSource.Play();
choiceUI.SetActive(false); // Hide UI after choice
Debug.Log("Phone Answered! Loading GoodEnding...");
choiceUI.SetActive(false);
SceneManager.LoadScene("GoodEnding");
}
void DeclineCall()
private void DeclineCall()
{
choiceMade = true;
Debug.Log("Call Declined! Loading 'House' scene...");
Debug.Log("Call Declined! Loading BadEnding...");
choiceUI.SetActive(false);
SceneManager.LoadScene("BadEnding");
}
}

Binary file not shown.

View file

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