tried some stuff
This commit is contained in:
parent
2870632864
commit
3e8481d6ea
@ -919,6 +919,7 @@ GameObject:
|
||||
- component: {fileID: 274103194}
|
||||
- component: {fileID: 274103193}
|
||||
- component: {fileID: 274103192}
|
||||
- component: {fileID: 274103195}
|
||||
m_Layer: 0
|
||||
m_Name: Beaver
|
||||
m_TagString: Interactable
|
||||
@ -986,6 +987,33 @@ Transform:
|
||||
- {fileID: 243848965}
|
||||
m_Father: {fileID: 0}
|
||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||
--- !u!54 &274103195
|
||||
Rigidbody:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 274103191}
|
||||
serializedVersion: 4
|
||||
m_Mass: 1
|
||||
m_Drag: 0
|
||||
m_AngularDrag: 0.05
|
||||
m_CenterOfMass: {x: 0, y: 0, z: 0}
|
||||
m_InertiaTensor: {x: 1, y: 1, z: 1}
|
||||
m_InertiaRotation: {x: 0, y: 0, z: 0, w: 1}
|
||||
m_IncludeLayers:
|
||||
serializedVersion: 2
|
||||
m_Bits: 0
|
||||
m_ExcludeLayers:
|
||||
serializedVersion: 2
|
||||
m_Bits: 0
|
||||
m_ImplicitCom: 1
|
||||
m_ImplicitTensor: 1
|
||||
m_UseGravity: 1
|
||||
m_IsKinematic: 1
|
||||
m_Interpolate: 0
|
||||
m_Constraints: 0
|
||||
m_CollisionDetection: 0
|
||||
--- !u!1001 &333271331
|
||||
PrefabInstance:
|
||||
m_ObjectHideFlags: 0
|
||||
|
@ -1,3 +1,4 @@
|
||||
using System.Collections;
|
||||
using UnityEngine;
|
||||
using TMPro;
|
||||
using UnityEngine.UI;
|
||||
@ -16,10 +17,25 @@ public class DialogManager : MonoBehaviour
|
||||
public void ShowDialog(string message)
|
||||
{
|
||||
print("should be showing dialog");
|
||||
dialogText.text = message;
|
||||
StartCoroutine(ShowDialogCoroutine(message));
|
||||
dialogPanel.SetActive(true);
|
||||
playerMovement.moveAllowed = false;
|
||||
}
|
||||
|
||||
// Coroutine to show dialog. Each letter is displayed one by one
|
||||
IEnumerator ShowDialogCoroutine(string message)
|
||||
{
|
||||
dialogText.text = ""; // Clear previous text
|
||||
dialogPanel.SetActive(true);
|
||||
playerMovement.moveAllowed = false;
|
||||
|
||||
foreach (char letter in message)
|
||||
{
|
||||
dialogText.text += letter; // Append each letter
|
||||
// KRAUSI MACH SOUND HIER DRINNE REIN PRO LETTER
|
||||
yield return new WaitForSeconds(0.05f); // Wait for a short duration before showing the next letter
|
||||
}
|
||||
}
|
||||
|
||||
public void HideDialog()
|
||||
{
|
||||
|
@ -19,6 +19,7 @@ public class PlayerInteraction : MonoBehaviour
|
||||
[SerializeField] private GameObject dialogManagerObject;
|
||||
|
||||
private DialogManager dialogManager;
|
||||
private List<GameObject> interactableObjects = new List<GameObject>();
|
||||
void Start()
|
||||
{
|
||||
InteractAction.action.Enable();
|
||||
@ -34,32 +35,59 @@ public class PlayerInteraction : MonoBehaviour
|
||||
{
|
||||
if (context.performed)
|
||||
{
|
||||
Ray ray = new Ray(transform.position, transform.forward);
|
||||
RaycastHit hit;
|
||||
|
||||
if (Physics.Raycast(ray, out hit, interactRange))
|
||||
|
||||
GameObject speaker = interactableObjects.Count > 0 ? ColliderInteractable() : PhysicsRaycastInteractable();
|
||||
|
||||
dialog = speaker.GetComponent<QuestGiver>().Talk();
|
||||
// immedeately start the dialog
|
||||
dialogManager.ShowDialog("<b>" + dialog[dialogIndex].speaker + ": " + dialog[dialogIndex].text);
|
||||
// skip the 0th dialog entry since it has already been shown
|
||||
dialogIndex++;
|
||||
if (dialogIndex >= dialog.Length)
|
||||
{
|
||||
if (hit.collider.CompareTag("Interactable"))
|
||||
{
|
||||
//Debug.Log("Interacted with: " + hit.collider.name);
|
||||
// You can add more actions here
|
||||
dialog = hit.collider.GetComponent<QuestGiver>().Talk();
|
||||
// immedeately start the dialog
|
||||
dialogManager.ShowDialog(dialog[dialogIndex].speaker + ": " + dialog[dialogIndex].text);
|
||||
// skip the 0th dialog entry since it has already been shown
|
||||
dialogIndex++;
|
||||
if (dialogIndex >= dialog.Length)
|
||||
{
|
||||
// reset the dialog index if we reach the end of the dialog
|
||||
dialogIndex = 0;
|
||||
// reset the dialog to be null so it cannot be scrolled through when not in an interaction
|
||||
dialog = null;
|
||||
dialogManager.HideDialog();
|
||||
}
|
||||
}
|
||||
// reset the dialog index if we reach the end of the dialog
|
||||
dialogIndex = 0;
|
||||
// reset the dialog to be null so it cannot be scrolled through when not in an interaction
|
||||
dialog = null;
|
||||
dialogManager.HideDialog();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private GameObject PhysicsRaycastInteractable()
|
||||
{
|
||||
Ray ray = new Ray(transform.position, transform.forward);
|
||||
RaycastHit hit;
|
||||
|
||||
if (Physics.Raycast(ray, out hit, interactRange))
|
||||
{
|
||||
if (hit.collider.CompareTag("Interactable"))
|
||||
{
|
||||
//Debug.Log("Interacted with: " + hit.collider.name);
|
||||
// You can add more actions here
|
||||
return hit.collider.gameObject;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private GameObject ColliderInteractable()
|
||||
{
|
||||
print("test");
|
||||
float closestDistance = float.MaxValue;
|
||||
int pos = -1;
|
||||
for (int i = 0; i < interactableObjects.Count; i++)
|
||||
{
|
||||
if ((interactableObjects[i].transform.position - transform.position).magnitude < closestDistance)
|
||||
{
|
||||
closestDistance = (interactableObjects[i].transform.position - transform.position).magnitude;
|
||||
pos = i;
|
||||
}
|
||||
}
|
||||
|
||||
return interactableObjects[pos];
|
||||
}
|
||||
|
||||
void onDialogContinue(InputAction.CallbackContext context)
|
||||
{
|
||||
@ -82,9 +110,22 @@ public class PlayerInteraction : MonoBehaviour
|
||||
}
|
||||
}
|
||||
|
||||
void Update()
|
||||
private void OnTriggerEnter(Collision other)
|
||||
{
|
||||
|
||||
print("outside");
|
||||
if (other.gameObject.tag == "Interactable")
|
||||
{
|
||||
print("inside");
|
||||
interactableObjects.Add(other.gameObject);
|
||||
}
|
||||
}
|
||||
|
||||
private void OnTriggerExit(Collision other)
|
||||
{
|
||||
if (other.gameObject.tag == "Interactable")
|
||||
{
|
||||
interactableObjects.Remove(other.gameObject);
|
||||
}
|
||||
}
|
||||
|
||||
public void CollectBlueberry(int newBlueberries)
|
||||
|
Loading…
Reference in New Issue
Block a user