hiding place sctipts and player interaction
This commit is contained in:
23
Assets/Scripts/Evidence.cs
Normal file
23
Assets/Scripts/Evidence.cs
Normal file
@@ -0,0 +1,23 @@
|
||||
using UnityEngine;
|
||||
|
||||
public class Evidence : MonoBehaviour, IInteractable
|
||||
{
|
||||
public ItemType type;
|
||||
public bool isContraband;
|
||||
|
||||
public string GetInteractionText(PlayerInteraction player)
|
||||
{
|
||||
// Ha már van nála valami, nem veheti fel
|
||||
if (player.GetHeldEvidence() != null) return "Tele van a kezed!";
|
||||
return $"Felvétel: {type}";
|
||||
}
|
||||
|
||||
public void Interact(PlayerInteraction player)
|
||||
{
|
||||
// Ha üres a keze, odaadjuk neki ezt a tárgyat
|
||||
if (player.GetHeldEvidence() == null)
|
||||
{
|
||||
player.PickUpItem(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/Evidence.cs.meta
Normal file
11
Assets/Scripts/Evidence.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f4f90c9a94952804f9fb058c3f40aa48
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
23
Assets/Scripts/HidingPlaceManager.cs
Normal file
23
Assets/Scripts/HidingPlaceManager.cs
Normal file
@@ -0,0 +1,23 @@
|
||||
using UnityEngine;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
public class HidingPlaceManager : MonoBehaviour
|
||||
{
|
||||
public static HidingPlaceManager Instance { get; private set; }
|
||||
|
||||
// Az összes pályán lévő rejtekhely
|
||||
private HidingSpot[] allHidingSpots;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
Instance = this;
|
||||
allHidingSpots = FindObjectsOfType<HidingSpot>();
|
||||
}
|
||||
|
||||
// A rendőrök ezt hívják meg, amikor bejönnek
|
||||
public List<HidingSpot> GetSpotsForPoliceToCheck()
|
||||
{
|
||||
return allHidingSpots.OrderBy(x => Random.value).Take(Mathf.Max(1, allHidingSpots.Length / 3)).ToList();
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/HidingPlaceManager.cs.meta
Normal file
11
Assets/Scripts/HidingPlaceManager.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1d8a22ea902972845a8596763c2ecb09
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
52
Assets/Scripts/HidingSpot.cs
Normal file
52
Assets/Scripts/HidingSpot.cs
Normal file
@@ -0,0 +1,52 @@
|
||||
using UnityEngine;
|
||||
using System.Collections.Generic;
|
||||
|
||||
public class HidingSpot : MonoBehaviour, IInteractable
|
||||
{
|
||||
public string spotName;
|
||||
public List<HidingStep> steps;
|
||||
|
||||
private int currentStepIndex = 0;
|
||||
public bool IsFullyHidden => currentStepIndex >= steps.Count;
|
||||
public bool ContainsContraband { get; private set; }
|
||||
|
||||
public string GetInteractionText(PlayerInteraction player)
|
||||
{
|
||||
if (IsFullyHidden) return "Kész!";
|
||||
|
||||
HidingStep nextStep = steps[currentStepIndex];
|
||||
ItemType playerHeldItem = player.GetHeldItemType();
|
||||
|
||||
if (playerHeldItem == nextStep.requiredItem)
|
||||
{
|
||||
return nextStep.promptText;
|
||||
}
|
||||
|
||||
return $"Szükséged van erre: {nextStep.requiredItem}";
|
||||
}
|
||||
|
||||
public void Interact(PlayerInteraction player)
|
||||
{
|
||||
if (IsFullyHidden) return;
|
||||
|
||||
HidingStep nextStep = steps[currentStepIndex];
|
||||
Evidence heldEvidence = player.GetHeldEvidence();
|
||||
|
||||
if (heldEvidence != null && heldEvidence.type == nextStep.requiredItem)
|
||||
{
|
||||
if (heldEvidence.isContraband) ContainsContraband = true;
|
||||
|
||||
// Tárgy eltávolítása a kézből
|
||||
if (nextStep.consumeItem)
|
||||
{
|
||||
player.RemoveHeldItem();
|
||||
Destroy(heldEvidence.gameObject);
|
||||
}
|
||||
|
||||
nextStep.OnStepCompleted?.Invoke();
|
||||
|
||||
currentStepIndex++;
|
||||
Debug.Log($"{spotName}: Lépés teljesítve! ({currentStepIndex}/{steps.Count})");
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/HidingSpot.cs.meta
Normal file
11
Assets/Scripts/HidingSpot.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0d232895ff247e2459b377608e035d43
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
19
Assets/Scripts/HidingStep.cs
Normal file
19
Assets/Scripts/HidingStep.cs
Normal file
@@ -0,0 +1,19 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Events;
|
||||
|
||||
[Serializable]
|
||||
public class HidingStep
|
||||
{
|
||||
[Tooltip("A UI-on megjelenő szöveg ehhez a lépéshez, pl: 'Öntsd be a port'")]
|
||||
public string promptText;
|
||||
|
||||
[Tooltip("Milyen tárgy kell ehhez a lépéshez?")]
|
||||
public ItemType requiredItem;
|
||||
|
||||
[Tooltip("Elpusztuljon a tárgy a játékos kezéből a lépés után?")]
|
||||
public bool consumeItem = true;
|
||||
|
||||
[Tooltip("Mi történjen vizuálisan? (Animáció, hang, stb.)")]
|
||||
public UnityEvent OnStepCompleted;
|
||||
}
|
||||
11
Assets/Scripts/HidingStep.cs.meta
Normal file
11
Assets/Scripts/HidingStep.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5ee8deea0525ef44fab0f5bcb9cdd67a
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
6
Assets/Scripts/IInteractable.cs
Normal file
6
Assets/Scripts/IInteractable.cs
Normal file
@@ -0,0 +1,6 @@
|
||||
public interface IInteractable
|
||||
{
|
||||
// Átadjuk a playert, hogy tudjuk, mivel interaktál
|
||||
void Interact(PlayerInteraction player);
|
||||
string GetInteractionText(PlayerInteraction player);
|
||||
}
|
||||
11
Assets/Scripts/IInteractable.cs.meta
Normal file
11
Assets/Scripts/IInteractable.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 57babe414c5fd5846a8d5fd7b8c2e1e9
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
1
Assets/Scripts/ItemType.cs
Normal file
1
Assets/Scripts/ItemType.cs
Normal file
@@ -0,0 +1 @@
|
||||
public enum ItemType { None, Powder, Body, Flour, Sunglasses, MixerBowl }
|
||||
11
Assets/Scripts/ItemType.cs.meta
Normal file
11
Assets/Scripts/ItemType.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 067ef8f9a44619948a54f090a09cfd33
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
108
Assets/Scripts/PlayerInteraction.cs
Normal file
108
Assets/Scripts/PlayerInteraction.cs
Normal file
@@ -0,0 +1,108 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.InputSystem;
|
||||
|
||||
public class PlayerInteraction : MonoBehaviour
|
||||
{
|
||||
[Header("Beállítások")]
|
||||
public Camera playerCamera;
|
||||
public float interactRange = 3f;
|
||||
public Transform holdPosition; // Egy üres GameObject a kamera előtt, ahova a felvett tárgy ugrik
|
||||
|
||||
[Header("Állapot (Inspectorban látható)")]
|
||||
[SerializeField] private Evidence currentlyHeldEvidence = null;
|
||||
|
||||
private InputMaster input;
|
||||
private IInteractable currentTarget;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
input = new InputMaster();
|
||||
input.Player.Fire.Enable();
|
||||
input.Player.Fire.performed += ctx => OnInteract();
|
||||
}
|
||||
|
||||
private void OnEnable() => input.Enable();
|
||||
private void OnDisable() => input.Disable();
|
||||
|
||||
private void Update()
|
||||
{
|
||||
// 1. LÁTÁS: Raycast a kamera közepéből
|
||||
Ray ray = new Ray(playerCamera.transform.position, playerCamera.transform.forward);
|
||||
RaycastHit hit;
|
||||
|
||||
if (Physics.Raycast(ray, out hit, interactRange))
|
||||
{
|
||||
// Megnézzük, van-e a célpontba vett tárgyon IInteractable (pl. HidingSpot vagy Evidence)
|
||||
IInteractable interactable = hit.collider.GetComponent<IInteractable>();
|
||||
|
||||
if (interactable != null)
|
||||
{
|
||||
currentTarget = interactable;
|
||||
|
||||
// Itt tudod frissíteni a UI-t! Pl:
|
||||
// UIManager.Instance.ShowCrosshairText(currentTarget.GetInteractionText(this));
|
||||
} else
|
||||
{
|
||||
ClearTarget();
|
||||
}
|
||||
} else
|
||||
{
|
||||
ClearTarget();
|
||||
}
|
||||
}
|
||||
|
||||
private void ClearTarget()
|
||||
{
|
||||
currentTarget = null;
|
||||
// UIManager.Instance.HideCrosshairText();
|
||||
}
|
||||
|
||||
// 2. CSELEKVÉS: Ezt hívja meg az Input System, ha kattintottál
|
||||
private void OnInteract()
|
||||
{
|
||||
if (currentTarget != null)
|
||||
{
|
||||
// Átadjuk "saját magunkat" (this), hogy a rejtekhely tudja, minket kell vizsgálni
|
||||
currentTarget.Interact(this);
|
||||
}
|
||||
}
|
||||
|
||||
// 3. INVENTORY RENDSZER (A Rejtekhelyek ezeket hívják meg)
|
||||
|
||||
// Lekéri, mit tartunk a kézben
|
||||
public ItemType GetHeldItemType()
|
||||
{
|
||||
if (currentlyHeldEvidence != null)
|
||||
return currentlyHeldEvidence.type;
|
||||
|
||||
return ItemType.None;
|
||||
}
|
||||
|
||||
public Evidence GetHeldEvidence()
|
||||
{
|
||||
return currentlyHeldEvidence;
|
||||
}
|
||||
|
||||
// A rejtekhely hívja meg, amikor elnyeli a tárgyat
|
||||
public void RemoveHeldItem()
|
||||
{
|
||||
currentlyHeldEvidence = null;
|
||||
}
|
||||
|
||||
// A felvehető tárgyak (Evidence) hívják meg magukon, amikor rákattintasz
|
||||
public void PickUpItem(Evidence newEvidence)
|
||||
{
|
||||
if (currentlyHeldEvidence != null) return; // Már tele van a kezünk
|
||||
|
||||
currentlyHeldEvidence = newEvidence;
|
||||
|
||||
// Vizuálisan a kezünkbe (kamera elé) tesszük a tárgyat
|
||||
currentlyHeldEvidence.transform.SetParent(holdPosition);
|
||||
currentlyHeldEvidence.transform.localPosition = Vector3.zero;
|
||||
currentlyHeldEvidence.transform.localRotation = Quaternion.identity;
|
||||
|
||||
// Kikapcsoljuk a fizikáját, hogy ne essen le
|
||||
if (currentlyHeldEvidence.TryGetComponent(out Rigidbody rb)) rb.isKinematic = true;
|
||||
if (currentlyHeldEvidence.TryGetComponent(out Collider col)) col.enabled = false;
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/PlayerInteraction.cs.meta
Normal file
11
Assets/Scripts/PlayerInteraction.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f1ab2c2e74d48ea4ba17dddc0ed0230c
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -58,4 +58,10 @@ public class PlayerMovement : MonoBehaviour
|
||||
_inputMaster.Player.Move.Disable();
|
||||
_inputMaster.Player.Jump.Disable();
|
||||
}
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
_inputMaster.Player.Move.Enable();
|
||||
_inputMaster.Player.Jump.Enable();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user