Spaces:
Running
Running
Upload 18 files
Browse files- Scripts/Actor.cs +46 -0
- Scripts/ActorManager.cs +80 -0
- Scripts/AudioManager.cs +82 -0
- Scripts/CrabHandler.cs +429 -0
- Scripts/CrabInteract.cs +29 -0
- Scripts/CrabInterface.cs +154 -0
- Scripts/EquipmentController.cs +95 -0
- Scripts/FirstPersonController.cs +142 -0
- Scripts/GameManager.cs +101 -0
- Scripts/InteractHandler.cs +34 -0
- Scripts/InteractManager.cs +73 -0
- Scripts/LogManager.cs +174 -0
- Scripts/LogUI.cs +26 -0
- Scripts/PickupObject.cs +49 -0
- Scripts/Player.cs +14 -0
- Scripts/ReloadScene.cs +13 -0
- Scripts/StarterAssetsInputs.cs +247 -0
- Scripts/UICrabAnimator.cs +16 -0
Scripts/Actor.cs
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
using System;
|
| 2 |
+
using System.Collections;
|
| 3 |
+
using System.Collections.Generic;
|
| 4 |
+
using UnityEngine;
|
| 5 |
+
|
| 6 |
+
public class Actor : MonoBehaviour
|
| 7 |
+
{
|
| 8 |
+
public GameObject target;
|
| 9 |
+
public List<string> actorTypes;
|
| 10 |
+
public List<Objective> objectiveList;
|
| 11 |
+
private Outline outline;
|
| 12 |
+
public GameObject prefabReference;
|
| 13 |
+
|
| 14 |
+
void Start()
|
| 15 |
+
{
|
| 16 |
+
target = gameObject;
|
| 17 |
+
outline = GetComponent<Outline>();
|
| 18 |
+
ActorManager.Instance.RegisterActor(this);
|
| 19 |
+
}
|
| 20 |
+
|
| 21 |
+
public bool HasType(string type)
|
| 22 |
+
{
|
| 23 |
+
return actorTypes.Contains(type);
|
| 24 |
+
}
|
| 25 |
+
|
| 26 |
+
void Update()
|
| 27 |
+
{
|
| 28 |
+
if (outline == null || !this) return;
|
| 29 |
+
outline.enabled = ShouldHighlight();
|
| 30 |
+
}
|
| 31 |
+
|
| 32 |
+
|
| 33 |
+
private bool ShouldHighlight()
|
| 34 |
+
{
|
| 35 |
+
if (ObjectiveManager.Instance == null) return false;
|
| 36 |
+
|
| 37 |
+
foreach (var activeObjective in ObjectiveManager.Instance.activeObjectives)
|
| 38 |
+
{
|
| 39 |
+
if (objectiveList.Contains(activeObjective.objective))
|
| 40 |
+
{
|
| 41 |
+
return true;
|
| 42 |
+
}
|
| 43 |
+
}
|
| 44 |
+
return false;
|
| 45 |
+
}
|
| 46 |
+
}
|
Scripts/ActorManager.cs
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
using UnityEngine;
|
| 2 |
+
using System.Collections.Generic;
|
| 3 |
+
|
| 4 |
+
[System.Serializable]
|
| 5 |
+
public class ActorData
|
| 6 |
+
{
|
| 7 |
+
public GameObject prefab;
|
| 8 |
+
public Vector3 originalPosition;
|
| 9 |
+
public Quaternion originalRotation;
|
| 10 |
+
}
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
public class ActorManager : MonoBehaviour
|
| 14 |
+
{
|
| 15 |
+
public static ActorManager Instance;
|
| 16 |
+
|
| 17 |
+
private Dictionary<Actor, ActorData> actorOriginals = new();
|
| 18 |
+
private List<Actor> activeActors = new();
|
| 19 |
+
|
| 20 |
+
void Awake()
|
| 21 |
+
{
|
| 22 |
+
if (Instance != null && Instance != this)
|
| 23 |
+
Destroy(gameObject);
|
| 24 |
+
else
|
| 25 |
+
Instance = this;
|
| 26 |
+
}
|
| 27 |
+
|
| 28 |
+
public void RegisterActor(Actor actor)
|
| 29 |
+
{
|
| 30 |
+
if (actorOriginals.ContainsKey(actor)) return;
|
| 31 |
+
|
| 32 |
+
GameObject clone = Instantiate(actor.gameObject);
|
| 33 |
+
clone.SetActive(false);
|
| 34 |
+
clone.transform.SetParent(transform);
|
| 35 |
+
|
| 36 |
+
actorOriginals[actor] = new ActorData
|
| 37 |
+
{
|
| 38 |
+
prefab = actor.prefabReference,
|
| 39 |
+
originalPosition = actor.transform.position,
|
| 40 |
+
originalRotation = actor.transform.rotation
|
| 41 |
+
};
|
| 42 |
+
|
| 43 |
+
activeActors.Add(actor);
|
| 44 |
+
}
|
| 45 |
+
|
| 46 |
+
public void ResetActor(Actor actor)
|
| 47 |
+
{
|
| 48 |
+
if (!actorOriginals.TryGetValue(actor, out var data)) return;
|
| 49 |
+
|
| 50 |
+
Destroy(actor.gameObject);
|
| 51 |
+
|
| 52 |
+
GameObject newActorGO = Instantiate(data.prefab, data.originalPosition, data.originalRotation);
|
| 53 |
+
newActorGO.SetActive(true);
|
| 54 |
+
|
| 55 |
+
Actor newActor = newActorGO.GetComponent<Actor>();
|
| 56 |
+
actorOriginals.Remove(actor);
|
| 57 |
+
actorOriginals[newActor] = data;
|
| 58 |
+
|
| 59 |
+
activeActors.Remove(actor);
|
| 60 |
+
activeActors.Add(newActor);
|
| 61 |
+
}
|
| 62 |
+
|
| 63 |
+
public void ResetAllForObjective(Objective obj)
|
| 64 |
+
{
|
| 65 |
+
List<Actor> toReset = new();
|
| 66 |
+
|
| 67 |
+
foreach (var actor in activeActors)
|
| 68 |
+
{
|
| 69 |
+
if (actor != null && actor.objectiveList.Contains(obj))
|
| 70 |
+
{
|
| 71 |
+
toReset.Add(actor);
|
| 72 |
+
}
|
| 73 |
+
}
|
| 74 |
+
|
| 75 |
+
foreach (var actor in toReset)
|
| 76 |
+
{
|
| 77 |
+
ResetActor(actor);
|
| 78 |
+
}
|
| 79 |
+
}
|
| 80 |
+
}
|
Scripts/AudioManager.cs
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
using UnityEngine;
|
| 2 |
+
using UnityEngine.Audio;
|
| 3 |
+
using System.Collections;
|
| 4 |
+
|
| 5 |
+
public class AudioManager : MonoBehaviour
|
| 6 |
+
{
|
| 7 |
+
public static AudioManager Instance { get; private set; }
|
| 8 |
+
|
| 9 |
+
public AudioMixer mixer;
|
| 10 |
+
public AudioSource musicSource;
|
| 11 |
+
public string musicVolumeParam = "MusicVolume";
|
| 12 |
+
public float fadeDuration = 1.0f;
|
| 13 |
+
|
| 14 |
+
[Range(-80f, 0f)] public float targetVolume = 0f; // 0 dB = full volume
|
| 15 |
+
[Range(-80f, 0f)] public float muteVolume = -80f;
|
| 16 |
+
|
| 17 |
+
private Coroutine currentFadeCoroutine;
|
| 18 |
+
|
| 19 |
+
public string radioEQParam = "RadioEQ";
|
| 20 |
+
public float radioEQOnGain = 0f; // 0 dB
|
| 21 |
+
public float radioEQOffGain = -80f; // Essentially muted
|
| 22 |
+
|
| 23 |
+
private void Awake()
|
| 24 |
+
{
|
| 25 |
+
if (Instance != null && Instance != this)
|
| 26 |
+
{
|
| 27 |
+
Destroy(gameObject);
|
| 28 |
+
return;
|
| 29 |
+
}
|
| 30 |
+
|
| 31 |
+
Instance = this;
|
| 32 |
+
DontDestroyOnLoad(gameObject);
|
| 33 |
+
}
|
| 34 |
+
|
| 35 |
+
private void Start()
|
| 36 |
+
{
|
| 37 |
+
if (!musicSource.isPlaying)
|
| 38 |
+
{
|
| 39 |
+
musicSource.Play();
|
| 40 |
+
}
|
| 41 |
+
|
| 42 |
+
mixer.SetFloat(musicVolumeParam, muteVolume);
|
| 43 |
+
}
|
| 44 |
+
|
| 45 |
+
public void FadeGameTheme(bool fadeIn, bool instant = false)
|
| 46 |
+
{
|
| 47 |
+
if (currentFadeCoroutine != null)
|
| 48 |
+
StopCoroutine(currentFadeCoroutine);
|
| 49 |
+
|
| 50 |
+
if (instant)
|
| 51 |
+
{
|
| 52 |
+
mixer.SetFloat(musicVolumeParam, fadeIn ? targetVolume : muteVolume);
|
| 53 |
+
}
|
| 54 |
+
else
|
| 55 |
+
{
|
| 56 |
+
currentFadeCoroutine = StartCoroutine(FadeMixerGroupVolume(fadeIn));
|
| 57 |
+
}
|
| 58 |
+
}
|
| 59 |
+
|
| 60 |
+
public void ToggleRadioEQ(bool on)
|
| 61 |
+
{
|
| 62 |
+
float gain = on ? radioEQOnGain : radioEQOffGain;
|
| 63 |
+
mixer.SetFloat(radioEQParam, gain);
|
| 64 |
+
}
|
| 65 |
+
|
| 66 |
+
private IEnumerator FadeMixerGroupVolume(bool fadeIn)
|
| 67 |
+
{
|
| 68 |
+
mixer.GetFloat(musicVolumeParam, out float startVolume);
|
| 69 |
+
float endVolume = fadeIn ? targetVolume : muteVolume;
|
| 70 |
+
|
| 71 |
+
float time = 0f;
|
| 72 |
+
while (time < fadeDuration)
|
| 73 |
+
{
|
| 74 |
+
float newVolume = Mathf.Lerp(startVolume, endVolume, time / fadeDuration);
|
| 75 |
+
mixer.SetFloat(musicVolumeParam, newVolume);
|
| 76 |
+
time += Time.deltaTime;
|
| 77 |
+
yield return null;
|
| 78 |
+
}
|
| 79 |
+
|
| 80 |
+
mixer.SetFloat(musicVolumeParam, endVolume);
|
| 81 |
+
}
|
| 82 |
+
}
|
Scripts/CrabHandler.cs
ADDED
|
@@ -0,0 +1,429 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
using System;
|
| 2 |
+
using System.Collections;
|
| 3 |
+
using System.Collections.Generic;
|
| 4 |
+
using UnityEngine;
|
| 5 |
+
using UnityEngine.AI;
|
| 6 |
+
using UnityEngine.Animations.Rigging;
|
| 7 |
+
|
| 8 |
+
public class CrabHandler : MonoBehaviour
|
| 9 |
+
{
|
| 10 |
+
[Copyable] public Transform target;
|
| 11 |
+
private NavMeshAgent agent;
|
| 12 |
+
|
| 13 |
+
[Copyable] public float standStillRadius = 10.0f;
|
| 14 |
+
[Copyable] public float fleeRadius = 6.0f;
|
| 15 |
+
[Copyable] public float superSpeedRadius = 3.0f;
|
| 16 |
+
[Copyable] public float raycastLength = 2.0f;
|
| 17 |
+
|
| 18 |
+
private Quaternion targetRotation;
|
| 19 |
+
[Copyable] public bool shouldFlee = true;
|
| 20 |
+
[Copyable] public float normalSpeed = 3.5f;
|
| 21 |
+
[Copyable] public float superSpeed = 8.0f;
|
| 22 |
+
|
| 23 |
+
[Copyable] public bool isCarryingObject = false;
|
| 24 |
+
private GameObject carriedObject;
|
| 25 |
+
private GameManager gm;
|
| 26 |
+
[Copyable] public CrabBehavior crabBehavior;
|
| 27 |
+
[Copyable] public string targetingType;
|
| 28 |
+
|
| 29 |
+
[SerializeField] private bool startWithAgentDisabled = false;
|
| 30 |
+
private Animator animator;
|
| 31 |
+
private Rig carryRig;
|
| 32 |
+
|
| 33 |
+
void Start()
|
| 34 |
+
{
|
| 35 |
+
if (target == null)
|
| 36 |
+
target = GameObject.FindGameObjectWithTag("Player").transform;
|
| 37 |
+
|
| 38 |
+
agent = GetComponent<NavMeshAgent>();
|
| 39 |
+
agent.speed = normalSpeed;
|
| 40 |
+
gm = FindObjectOfType<GameManager>();
|
| 41 |
+
|
| 42 |
+
if (startWithAgentDisabled)
|
| 43 |
+
{
|
| 44 |
+
DisableAgentStuff();
|
| 45 |
+
}
|
| 46 |
+
|
| 47 |
+
if (carriedObject == null)
|
| 48 |
+
{
|
| 49 |
+
foreach (Transform child in transform)
|
| 50 |
+
{
|
| 51 |
+
if (child.CompareTag("PickUp"))
|
| 52 |
+
{
|
| 53 |
+
carriedObject = child.gameObject;
|
| 54 |
+
break;
|
| 55 |
+
}
|
| 56 |
+
}
|
| 57 |
+
}
|
| 58 |
+
|
| 59 |
+
animator = GetComponentInChildren<Animator>();
|
| 60 |
+
carryRig = GetComponentInChildren<Rig>();
|
| 61 |
+
}
|
| 62 |
+
|
| 63 |
+
|
| 64 |
+
void Update()
|
| 65 |
+
{
|
| 66 |
+
isCarryingObject = HasChildWithTag("PickUp");
|
| 67 |
+
|
| 68 |
+
if (!string.IsNullOrEmpty(targetingType))
|
| 69 |
+
{
|
| 70 |
+
target = FindNearestTarget(targetingType);
|
| 71 |
+
}
|
| 72 |
+
|
| 73 |
+
CarryObject();
|
| 74 |
+
|
| 75 |
+
if (target != null)
|
| 76 |
+
{
|
| 77 |
+
float distanceToPlayer = Vector3.Distance(target.position, transform.position);
|
| 78 |
+
Vector3 directionToPlayer = (target.position - agent.transform.position).normalized;
|
| 79 |
+
|
| 80 |
+
switch (crabBehavior)
|
| 81 |
+
{
|
| 82 |
+
case CrabBehavior.Flee:
|
| 83 |
+
HandleFleeBehavior(distanceToPlayer, directionToPlayer);
|
| 84 |
+
break;
|
| 85 |
+
|
| 86 |
+
case CrabBehavior.Follow:
|
| 87 |
+
HandleFollowBehavior(distanceToPlayer);
|
| 88 |
+
break;
|
| 89 |
+
|
| 90 |
+
case CrabBehavior.PickingUp:
|
| 91 |
+
HandlePickingUpBehavior(distanceToPlayer, directionToPlayer);
|
| 92 |
+
break;
|
| 93 |
+
|
| 94 |
+
case CrabBehavior.GoTo:
|
| 95 |
+
HandleGotoBehavior(distanceToPlayer, directionToPlayer);
|
| 96 |
+
break;
|
| 97 |
+
|
| 98 |
+
case CrabBehavior.DropItem:
|
| 99 |
+
DropObject();
|
| 100 |
+
break;
|
| 101 |
+
|
| 102 |
+
case CrabBehavior.StandStill:
|
| 103 |
+
HandleStandStillBehavior();
|
| 104 |
+
break;
|
| 105 |
+
|
| 106 |
+
}
|
| 107 |
+
|
| 108 |
+
|
| 109 |
+
}
|
| 110 |
+
else {
|
| 111 |
+
target = transform;
|
| 112 |
+
}
|
| 113 |
+
|
| 114 |
+
if (animator != null && agent != null)
|
| 115 |
+
{
|
| 116 |
+
float currentSpeed = agent.velocity.magnitude;
|
| 117 |
+
animator.SetFloat("CrabSpeed", currentSpeed);
|
| 118 |
+
}
|
| 119 |
+
|
| 120 |
+
}
|
| 121 |
+
|
| 122 |
+
void HandleFleeBehavior(float distanceToPlayer, Vector3 directionToPlayer)
|
| 123 |
+
{
|
| 124 |
+
|
| 125 |
+
if (distanceToPlayer > standStillRadius)
|
| 126 |
+
{
|
| 127 |
+
agent.ResetPath();
|
| 128 |
+
return;
|
| 129 |
+
}
|
| 130 |
+
else
|
| 131 |
+
{
|
| 132 |
+
agent.isStopped = false;
|
| 133 |
+
}
|
| 134 |
+
|
| 135 |
+
if (distanceToPlayer < superSpeedRadius)
|
| 136 |
+
{
|
| 137 |
+
agent.speed = superSpeed;
|
| 138 |
+
}
|
| 139 |
+
else
|
| 140 |
+
{
|
| 141 |
+
agent.speed = normalSpeed;
|
| 142 |
+
}
|
| 143 |
+
|
| 144 |
+
Vector3 targetPosition = agent.transform.position - directionToPlayer * fleeRadius;
|
| 145 |
+
|
| 146 |
+
NavMeshHit hit;
|
| 147 |
+
if (NavMesh.SamplePosition(targetPosition, out hit, fleeRadius, NavMesh.AllAreas))
|
| 148 |
+
{
|
| 149 |
+
agent.SetDestination(hit.position);
|
| 150 |
+
}
|
| 151 |
+
}
|
| 152 |
+
|
| 153 |
+
void HandleFollowBehavior(float distanceToPlayer)
|
| 154 |
+
{
|
| 155 |
+
Vector3 followTargetPosition = target.position;
|
| 156 |
+
|
| 157 |
+
NavMeshHit hit;
|
| 158 |
+
if (NavMesh.SamplePosition(followTargetPosition, out hit, fleeRadius, NavMesh.AllAreas))
|
| 159 |
+
{
|
| 160 |
+
agent.SetDestination(hit.position);
|
| 161 |
+
}
|
| 162 |
+
|
| 163 |
+
if (distanceToPlayer <= superSpeedRadius)
|
| 164 |
+
{
|
| 165 |
+
agent.isStopped = true;
|
| 166 |
+
}
|
| 167 |
+
else
|
| 168 |
+
{
|
| 169 |
+
agent.isStopped = false;
|
| 170 |
+
}
|
| 171 |
+
|
| 172 |
+
agent.speed = normalSpeed;
|
| 173 |
+
}
|
| 174 |
+
|
| 175 |
+
private float pickupRange = 2f;
|
| 176 |
+
|
| 177 |
+
void HandlePickingUpBehavior(float distanceToObject, Vector3 directionToObject)
|
| 178 |
+
{
|
| 179 |
+
if (target == null) return;
|
| 180 |
+
|
| 181 |
+
agent.isStopped = false;
|
| 182 |
+
|
| 183 |
+
if (distanceToObject > pickupRange)
|
| 184 |
+
{
|
| 185 |
+
Debug.Log("HELP ME IM IN GREAT PAIN");
|
| 186 |
+
agent.SetDestination(target.position);
|
| 187 |
+
agent.speed = normalSpeed;
|
| 188 |
+
return;
|
| 189 |
+
}
|
| 190 |
+
|
| 191 |
+
if (!isCarryingObject && target.CompareTag("PickUp"))
|
| 192 |
+
{
|
| 193 |
+
Debug.Log("Attempting pickup");
|
| 194 |
+
PickUpObject(target.gameObject);
|
| 195 |
+
}
|
| 196 |
+
}
|
| 197 |
+
|
| 198 |
+
void HandleGotoBehavior(float distanceToObject, Vector3 directionToObject)
|
| 199 |
+
{
|
| 200 |
+
agent.isStopped = false;
|
| 201 |
+
|
| 202 |
+
if (distanceToObject > 0.5f)
|
| 203 |
+
{
|
| 204 |
+
Debug.Log("HELP ME IM IN GREAT PAIN");
|
| 205 |
+
agent.SetDestination(target.position);
|
| 206 |
+
agent.speed = normalSpeed;
|
| 207 |
+
}
|
| 208 |
+
}
|
| 209 |
+
|
| 210 |
+
void HandleStandStillBehavior()
|
| 211 |
+
{
|
| 212 |
+
agent.isStopped = true;
|
| 213 |
+
agent.velocity = Vector3.zero;
|
| 214 |
+
}
|
| 215 |
+
|
| 216 |
+
void HandleGroundAlignmentAndRotation(Vector3 directionToPlayer)
|
| 217 |
+
{
|
| 218 |
+
RaycastHit groundHit;
|
| 219 |
+
if (Physics.Raycast(transform.position, Vector3.down, out groundHit, raycastLength))
|
| 220 |
+
{
|
| 221 |
+
Vector3 groundNormal = groundHit.normal;
|
| 222 |
+
targetRotation = Quaternion.FromToRotation(transform.up, groundNormal) * transform.rotation;
|
| 223 |
+
transform.rotation = targetRotation;
|
| 224 |
+
}
|
| 225 |
+
|
| 226 |
+
Vector3 directionToFace;
|
| 227 |
+
if (shouldFlee)
|
| 228 |
+
{
|
| 229 |
+
directionToFace = -directionToPlayer;
|
| 230 |
+
}
|
| 231 |
+
else
|
| 232 |
+
{
|
| 233 |
+
directionToFace = directionToPlayer;
|
| 234 |
+
}
|
| 235 |
+
|
| 236 |
+
directionToFace.y = 0;
|
| 237 |
+
Quaternion targetPlayerRotation = Quaternion.LookRotation(directionToFace);
|
| 238 |
+
|
| 239 |
+
transform.rotation = Quaternion.Slerp(transform.rotation, targetPlayerRotation, Time.deltaTime * 5f);
|
| 240 |
+
}
|
| 241 |
+
|
| 242 |
+
public void ApplyBoardTextEffects(List<string> confirmedWords)
|
| 243 |
+
{
|
| 244 |
+
targetingType = "";
|
| 245 |
+
|
| 246 |
+
foreach (string word in confirmedWords)
|
| 247 |
+
{
|
| 248 |
+
GameManager.WordEffect effect = gm.GetEffectForWord(word);
|
| 249 |
+
|
| 250 |
+
if (effect != null)
|
| 251 |
+
{
|
| 252 |
+
if (effect.affectFlee)
|
| 253 |
+
{
|
| 254 |
+
if (effect.crabBehavior == CrabBehavior.Flee)
|
| 255 |
+
{
|
| 256 |
+
crabBehavior = CrabBehavior.Flee;
|
| 257 |
+
}
|
| 258 |
+
else if (effect.crabBehavior == CrabBehavior.Follow)
|
| 259 |
+
{
|
| 260 |
+
crabBehavior = CrabBehavior.Follow;
|
| 261 |
+
}
|
| 262 |
+
else if (effect.crabBehavior == CrabBehavior.PickingUp)
|
| 263 |
+
{
|
| 264 |
+
crabBehavior = CrabBehavior.PickingUp;
|
| 265 |
+
}
|
| 266 |
+
else if (effect.crabBehavior == CrabBehavior.DropItem)
|
| 267 |
+
{
|
| 268 |
+
crabBehavior = CrabBehavior.DropItem;
|
| 269 |
+
}
|
| 270 |
+
else if (effect.crabBehavior == CrabBehavior.StandStill)
|
| 271 |
+
{
|
| 272 |
+
crabBehavior = CrabBehavior.StandStill;
|
| 273 |
+
}
|
| 274 |
+
else if (effect.crabBehavior == CrabBehavior.GoTo)
|
| 275 |
+
{
|
| 276 |
+
crabBehavior = CrabBehavior.GoTo;
|
| 277 |
+
}
|
| 278 |
+
}
|
| 279 |
+
|
| 280 |
+
if (effect.affectTarget)
|
| 281 |
+
{
|
| 282 |
+
if (effect._target != null)
|
| 283 |
+
{
|
| 284 |
+
target = effect._target.transform;
|
| 285 |
+
}
|
| 286 |
+
else if (!string.IsNullOrEmpty(effect.targetType))
|
| 287 |
+
{
|
| 288 |
+
targetingType = effect.targetType;
|
| 289 |
+
target = FindNearestTarget(effect.targetType);
|
| 290 |
+
}
|
| 291 |
+
}
|
| 292 |
+
}
|
| 293 |
+
}
|
| 294 |
+
}
|
| 295 |
+
|
| 296 |
+
|
| 297 |
+
|
| 298 |
+
private Transform FindNearestTarget(string targetType)
|
| 299 |
+
{
|
| 300 |
+
Actor[] actors = FindObjectsOfType<Actor>();
|
| 301 |
+
Transform nearestTarget = null;
|
| 302 |
+
float shortestDistance = Mathf.Infinity;
|
| 303 |
+
|
| 304 |
+
foreach (Actor actor in actors)
|
| 305 |
+
{
|
| 306 |
+
Transform actorTransform = actor.transform;
|
| 307 |
+
|
| 308 |
+
if (actor.HasType(targetType) && !IsSelfOrAncestor(actorTransform))
|
| 309 |
+
{
|
| 310 |
+
float distance = Vector3.Distance(transform.position, actorTransform.position);
|
| 311 |
+
if (distance < shortestDistance)
|
| 312 |
+
{
|
| 313 |
+
shortestDistance = distance;
|
| 314 |
+
nearestTarget = actorTransform;
|
| 315 |
+
}
|
| 316 |
+
}
|
| 317 |
+
}
|
| 318 |
+
|
| 319 |
+
return nearestTarget;
|
| 320 |
+
}
|
| 321 |
+
|
| 322 |
+
private bool IsSelfOrAncestor(Transform other)
|
| 323 |
+
{
|
| 324 |
+
Transform current = transform;
|
| 325 |
+
while (current != null)
|
| 326 |
+
{
|
| 327 |
+
if (other == current)
|
| 328 |
+
return true;
|
| 329 |
+
current = current.parent;
|
| 330 |
+
}
|
| 331 |
+
return false;
|
| 332 |
+
}
|
| 333 |
+
|
| 334 |
+
void PickUpObject(GameObject obj)
|
| 335 |
+
{
|
| 336 |
+
carriedObject = obj;
|
| 337 |
+
obj.transform.SetParent(transform);
|
| 338 |
+
carriedObject.transform.position = transform.position + new Vector3(0, 0.8f, 0);
|
| 339 |
+
carriedObject.transform.localRotation = Quaternion.identity;
|
| 340 |
+
|
| 341 |
+
Collider objCollider = obj.GetComponent<Collider>();
|
| 342 |
+
if (objCollider != null) objCollider.enabled = false;
|
| 343 |
+
|
| 344 |
+
Rigidbody rb = obj.GetComponent<Rigidbody>();
|
| 345 |
+
if (rb != null) rb.isKinematic = true;
|
| 346 |
+
|
| 347 |
+
NavMeshAgent agent = obj.GetComponent<NavMeshAgent>();
|
| 348 |
+
if (agent != null)
|
| 349 |
+
{
|
| 350 |
+
agent.isStopped = true;
|
| 351 |
+
agent.updatePosition = false;
|
| 352 |
+
agent.updateRotation = false;
|
| 353 |
+
}
|
| 354 |
+
}
|
| 355 |
+
|
| 356 |
+
|
| 357 |
+
void DropObject()
|
| 358 |
+
{
|
| 359 |
+
if (carriedObject != null)
|
| 360 |
+
{
|
| 361 |
+
carriedObject.transform.SetParent(null);
|
| 362 |
+
Vector3 dropOffset = transform.forward * 1.5f + Vector3.down * 0.2f;
|
| 363 |
+
carriedObject.transform.position = transform.position + dropOffset;
|
| 364 |
+
|
| 365 |
+
Collider col = carriedObject.GetComponent<Collider>();
|
| 366 |
+
if (col != null)
|
| 367 |
+
{
|
| 368 |
+
col.enabled = true;
|
| 369 |
+
}
|
| 370 |
+
|
| 371 |
+
Rigidbody rb = carriedObject.GetComponent<Rigidbody>();
|
| 372 |
+
if (rb == null)
|
| 373 |
+
{
|
| 374 |
+
rb = carriedObject.AddComponent<Rigidbody>();
|
| 375 |
+
}
|
| 376 |
+
|
| 377 |
+
EquipInteract equip = carriedObject.GetComponent<EquipInteract>();
|
| 378 |
+
if (equip != null) {
|
| 379 |
+
equip.interactable = true;
|
| 380 |
+
}
|
| 381 |
+
|
| 382 |
+
rb.isKinematic = false;
|
| 383 |
+
rb.linearVelocity = Vector3.down * 2f;
|
| 384 |
+
|
| 385 |
+
NavMeshAgent agent = carriedObject.GetComponent<NavMeshAgent>();
|
| 386 |
+
if (agent != null)
|
| 387 |
+
{
|
| 388 |
+
agent.isStopped = false;
|
| 389 |
+
agent.updatePosition = true;
|
| 390 |
+
agent.updateRotation = true;
|
| 391 |
+
}
|
| 392 |
+
|
| 393 |
+
carriedObject = null;
|
| 394 |
+
|
| 395 |
+
crabBehavior = CrabBehavior.Follow;
|
| 396 |
+
}
|
| 397 |
+
}
|
| 398 |
+
|
| 399 |
+
void DisableAgentStuff()
|
| 400 |
+
{
|
| 401 |
+
if (agent != null)
|
| 402 |
+
{
|
| 403 |
+
agent.isStopped = true;
|
| 404 |
+
agent.updatePosition = false;
|
| 405 |
+
agent.updateRotation = false;
|
| 406 |
+
}
|
| 407 |
+
}
|
| 408 |
+
|
| 409 |
+
void CarryObject()
|
| 410 |
+
{
|
| 411 |
+
if (carryRig != null)
|
| 412 |
+
{
|
| 413 |
+
carryRig.weight = isCarryingObject ? 1f : 0f;
|
| 414 |
+
}
|
| 415 |
+
}
|
| 416 |
+
|
| 417 |
+
bool HasChildWithTag(string tag)
|
| 418 |
+
{
|
| 419 |
+
foreach (Transform child in transform)
|
| 420 |
+
{
|
| 421 |
+
if (child.CompareTag(tag))
|
| 422 |
+
{
|
| 423 |
+
return true;
|
| 424 |
+
}
|
| 425 |
+
}
|
| 426 |
+
return false;
|
| 427 |
+
}
|
| 428 |
+
|
| 429 |
+
}
|
Scripts/CrabInteract.cs
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
using UnityEngine;
|
| 2 |
+
|
| 3 |
+
public class CrabInteract : InteractHandler
|
| 4 |
+
{
|
| 5 |
+
public GameObject commandUIPrefab;
|
| 6 |
+
public LogManager logman;
|
| 7 |
+
|
| 8 |
+
private GameObject currentUI;
|
| 9 |
+
|
| 10 |
+
void Start()
|
| 11 |
+
{
|
| 12 |
+
logman = FindObjectOfType<LogManager>();
|
| 13 |
+
}
|
| 14 |
+
|
| 15 |
+
public override void InteractLogic()
|
| 16 |
+
{
|
| 17 |
+
if (currentUI == null)
|
| 18 |
+
{
|
| 19 |
+
currentUI = Instantiate(commandUIPrefab);
|
| 20 |
+
currentUI.GetComponent<CrabInterface>().crab = GetComponent<CrabHandler>();
|
| 21 |
+
logman.SetCrabInterface(commandUIPrefab.GetComponent<CrabInterface>());
|
| 22 |
+
}
|
| 23 |
+
|
| 24 |
+
logman.ToggleLogMenu(true);
|
| 25 |
+
|
| 26 |
+
base.InteractLogic();
|
| 27 |
+
interactable = true;
|
| 28 |
+
}
|
| 29 |
+
}
|
Scripts/CrabInterface.cs
ADDED
|
@@ -0,0 +1,154 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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+
{
|
| 9 |
+
public TextMeshProUGUI boardText;
|
| 10 |
+
public Button clearButton;
|
| 11 |
+
public Button confirmButton;
|
| 12 |
+
public CrabHandler crab;
|
| 13 |
+
private HashSet<string> displayedWords = new HashSet<string>();
|
| 14 |
+
private const int maxWords = 2;
|
| 15 |
+
private GameManager gm;
|
| 16 |
+
public Animator animator;
|
| 17 |
+
public SpriteRenderer spriteRender;
|
| 18 |
+
|
| 19 |
+
private void Start()
|
| 20 |
+
{
|
| 21 |
+
GameObject uiCamObj = GameObject.FindGameObjectWithTag("UI");
|
| 22 |
+
Canvas canvas = GetComponent<Canvas>();
|
| 23 |
+
canvas.renderMode = RenderMode.ScreenSpaceCamera;
|
| 24 |
+
canvas.worldCamera = uiCamObj.GetComponent<Camera>();
|
| 25 |
+
canvas.planeDistance = 1f;
|
| 26 |
+
canvas.sortingLayerName = "UI";
|
| 27 |
+
canvas.sortingOrder = 500;
|
| 28 |
+
|
| 29 |
+
var renderers = GetComponentsInChildren<SpriteRenderer>();
|
| 30 |
+
foreach (var renderer in renderers)
|
| 31 |
+
{
|
| 32 |
+
renderer.sortingLayerName = "UI";
|
| 33 |
+
renderer.sortingOrder += 500;
|
| 34 |
+
}
|
| 35 |
+
|
| 36 |
+
|
| 37 |
+
LogManager logManager = FindObjectOfType<LogManager>();
|
| 38 |
+
gm = FindObjectOfType<GameManager>();
|
| 39 |
+
|
| 40 |
+
if (logManager != null)
|
| 41 |
+
{
|
| 42 |
+
logManager.SetCrabInterface(this);
|
| 43 |
+
}
|
| 44 |
+
|
| 45 |
+
if (clearButton != null)
|
| 46 |
+
{
|
| 47 |
+
clearButton.onClick.AddListener(ClearBoard);
|
| 48 |
+
}
|
| 49 |
+
|
| 50 |
+
if (confirmButton != null)
|
| 51 |
+
{
|
| 52 |
+
confirmButton.onClick.AddListener(ConfirmBoardText);
|
| 53 |
+
}
|
| 54 |
+
|
| 55 |
+
|
| 56 |
+
}
|
| 57 |
+
|
| 58 |
+
private void Update()
|
| 59 |
+
{
|
| 60 |
+
|
| 61 |
+
}
|
| 62 |
+
|
| 63 |
+
public void AddWordToBoard(string word)
|
| 64 |
+
{
|
| 65 |
+
if (displayedWords.Count >= maxWords)
|
| 66 |
+
{
|
| 67 |
+
return;
|
| 68 |
+
}
|
| 69 |
+
|
| 70 |
+
if (!displayedWords.Contains(word))
|
| 71 |
+
{
|
| 72 |
+
displayedWords.Add(word);
|
| 73 |
+
boardText.text = string.Join(", ", displayedWords);
|
| 74 |
+
GameManager.WordEffect effect = gm.GetEffectForWord(word);
|
| 75 |
+
|
| 76 |
+
if (effect != null)
|
| 77 |
+
{
|
| 78 |
+
if (effect.affectFlee) {
|
| 79 |
+
|
| 80 |
+
switch (effect.crabBehavior)
|
| 81 |
+
{
|
| 82 |
+
case CrabBehavior.Flee:
|
| 83 |
+
case CrabBehavior.GoTo:
|
| 84 |
+
case CrabBehavior.Follow:
|
| 85 |
+
SetBehavior(1);
|
| 86 |
+
Debug.Log("WE FOLLOW MUSK ON TWITTER");
|
| 87 |
+
break;
|
| 88 |
+
case CrabBehavior.PickingUp:
|
| 89 |
+
SetBehavior(4);
|
| 90 |
+
Debug.Log("WE PICK UP THE PHONE");
|
| 91 |
+
break;
|
| 92 |
+
case CrabBehavior.DropItem:
|
| 93 |
+
SetBehavior(3);
|
| 94 |
+
Debug.Log("WE DROP TILTED TOWERS");
|
| 95 |
+
break;
|
| 96 |
+
case CrabBehavior.StandStill:
|
| 97 |
+
SetBehavior(2);
|
| 98 |
+
Debug.Log("FREEZE!");
|
| 99 |
+
break;
|
| 100 |
+
default:
|
| 101 |
+
SetBehavior(0);
|
| 102 |
+
break;
|
| 103 |
+
}
|
| 104 |
+
}
|
| 105 |
+
|
| 106 |
+
if (effect.affectTarget)
|
| 107 |
+
{
|
| 108 |
+
spriteRender.sprite = effect.wordSprite;
|
| 109 |
+
|
| 110 |
+
if (spriteRender.sprite != null) {
|
| 111 |
+
float targetSize = 7f;
|
| 112 |
+
Vector2 spriteSize = effect.wordSprite.bounds.size;
|
| 113 |
+
|
| 114 |
+
float scaleFactor = targetSize / Mathf.Max(spriteSize.x, spriteSize.y);
|
| 115 |
+
spriteRender.transform.localScale = new Vector3(scaleFactor, scaleFactor, 1);
|
| 116 |
+
}
|
| 117 |
+
}
|
| 118 |
+
|
| 119 |
+
}
|
| 120 |
+
else
|
| 121 |
+
{
|
| 122 |
+
Debug.Log("MISSING MY LOVE");
|
| 123 |
+
}
|
| 124 |
+
}
|
| 125 |
+
}
|
| 126 |
+
|
| 127 |
+
public void SetBehavior(int behavior)
|
| 128 |
+
{
|
| 129 |
+
if (animator != null)
|
| 130 |
+
{
|
| 131 |
+
animator.SetFloat("BehaviorIndex", behavior);
|
| 132 |
+
}
|
| 133 |
+
}
|
| 134 |
+
|
| 135 |
+
public void ClearBoard()
|
| 136 |
+
{
|
| 137 |
+
displayedWords.Clear();
|
| 138 |
+
boardText.text = "";
|
| 139 |
+
SetBehavior(0);
|
| 140 |
+
spriteRender.sprite = null;
|
| 141 |
+
}
|
| 142 |
+
|
| 143 |
+
public void ConfirmBoardText()
|
| 144 |
+
{
|
| 145 |
+
if (crab == null || gm == null)
|
| 146 |
+
{
|
| 147 |
+
return;
|
| 148 |
+
}
|
| 149 |
+
|
| 150 |
+
List<string> wordsList = new List<string>(displayedWords);
|
| 151 |
+
crab.ApplyBoardTextEffects(wordsList);
|
| 152 |
+
ClearBoard();
|
| 153 |
+
}
|
| 154 |
+
}
|
Scripts/EquipmentController.cs
ADDED
|
@@ -0,0 +1,95 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
using System;
|
| 2 |
+
using System.Collections.Generic;
|
| 3 |
+
using UnityEngine;
|
| 4 |
+
using UnityEngine.UI;
|
| 5 |
+
using UnityEngine.Events;
|
| 6 |
+
|
| 7 |
+
public class EquipmentController : MonoBehaviour
|
| 8 |
+
{
|
| 9 |
+
public enum EquipmentType
|
| 10 |
+
{
|
| 11 |
+
None,
|
| 12 |
+
Weapon,
|
| 13 |
+
Tool,
|
| 14 |
+
Objective,
|
| 15 |
+
}
|
| 16 |
+
|
| 17 |
+
[Header("Information")]
|
| 18 |
+
[Tooltip("The name that will be displayed in the UI for this Equipment")]
|
| 19 |
+
public string EquipmentName;
|
| 20 |
+
|
| 21 |
+
[Tooltip("The image that will be displayed in the UI for this Equipment")]
|
| 22 |
+
public Image EquipmentIcon;
|
| 23 |
+
|
| 24 |
+
[Tooltip("The root object for the weapon, this is what will be deactivated when the weapon isn't active")]
|
| 25 |
+
public GameObject EquipmentRoot;
|
| 26 |
+
|
| 27 |
+
[Tooltip("The transform for the correct hand positioning of the equipment")]
|
| 28 |
+
public Transform EquipmentOffset;
|
| 29 |
+
|
| 30 |
+
[Tooltip("Tip of the Equipment, where the projectiles are shot (If a weapon")]
|
| 31 |
+
public Transform WeaponMuzzle;
|
| 32 |
+
|
| 33 |
+
[Tooltip("The type of Equipment wil affect how it is utilized")]
|
| 34 |
+
public EquipmentType EquipType;
|
| 35 |
+
|
| 36 |
+
[Tooltip("Check if Equipment is equipped")]
|
| 37 |
+
public bool Equipped;
|
| 38 |
+
|
| 39 |
+
[Tooltip("Maximum amount of ammo in the gun")]
|
| 40 |
+
public int MaxAmmo = 6;
|
| 41 |
+
public float CurrentAmmo = 6;
|
| 42 |
+
|
| 43 |
+
[Tooltip("The projectile prefab")] public GameObject ProjectilePrefab;
|
| 44 |
+
private StarterAssetsInputs _input;
|
| 45 |
+
|
| 46 |
+
// Start is called once before the first execution of Update after the MonoBehaviour is created
|
| 47 |
+
void Start()
|
| 48 |
+
{
|
| 49 |
+
_input = FindObjectOfType<StarterAssetsInputs>();
|
| 50 |
+
}
|
| 51 |
+
|
| 52 |
+
// Update is called once per frame
|
| 53 |
+
void Update()
|
| 54 |
+
{
|
| 55 |
+
switch (EquipType)
|
| 56 |
+
{
|
| 57 |
+
case EquipmentType.None:
|
| 58 |
+
// Maybe do nothing or add idle behavior
|
| 59 |
+
break;
|
| 60 |
+
|
| 61 |
+
case EquipmentType.Weapon:
|
| 62 |
+
if (Equipped)
|
| 63 |
+
{
|
| 64 |
+
// Example: Shooting logic, checking for input, etc.
|
| 65 |
+
Debug.Log("Weapon equipped.");
|
| 66 |
+
// if (_input.shoot) { Fire(); }
|
| 67 |
+
}
|
| 68 |
+
break;
|
| 69 |
+
|
| 70 |
+
case EquipmentType.Tool:
|
| 71 |
+
if (Equipped)
|
| 72 |
+
{
|
| 73 |
+
// Example: Use tool logic, maybe scanning or interacting
|
| 74 |
+
Debug.Log("Tool equipped.");
|
| 75 |
+
if (_input.aim) {
|
| 76 |
+
Instantiate(ProjectilePrefab, transform);
|
| 77 |
+
}
|
| 78 |
+
}
|
| 79 |
+
break;
|
| 80 |
+
|
| 81 |
+
case EquipmentType.Objective:
|
| 82 |
+
if (Equipped)
|
| 83 |
+
{
|
| 84 |
+
// Example: Carry or activate objective
|
| 85 |
+
Debug.Log("Objective equipped.");
|
| 86 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|
|
|
|
|
| 1 |
+
using System.Collections;
|
| 2 |
+
using System.Collections.Generic;
|
| 3 |
+
using UnityEngine;
|
| 4 |
+
using UnityEngine.InputSystem;
|
| 5 |
+
|
| 6 |
+
[RequireComponent(typeof(CharacterController))]
|
| 7 |
+
public class FirstPersonController : MonoBehaviour
|
| 8 |
+
{
|
| 9 |
+
[Header("Player")]
|
| 10 |
+
public float moveSpeed = 4.0f;
|
| 11 |
+
public float sprintSpeed = 6.0f;
|
| 12 |
+
public float crouchSpeed = 2.0f;
|
| 13 |
+
public float jumpHeight = 1.2f;
|
| 14 |
+
public float gravity = -15.0f;
|
| 15 |
+
|
| 16 |
+
[Header("Camera")]
|
| 17 |
+
public Transform cameraTransform;
|
| 18 |
+
public float cameraSensitivity = 1.0f;
|
| 19 |
+
public float maxCameraAngle = 85f;
|
| 20 |
+
|
| 21 |
+
[Header("Ground Check")]
|
| 22 |
+
public float groundCheckDistance = 0.4f;
|
| 23 |
+
public float groundCheckRadius = 0.3f;
|
| 24 |
+
public LayerMask groundLayer;
|
| 25 |
+
public bool isGrounded;
|
| 26 |
+
|
| 27 |
+
private float _fallTimeoutDelta;
|
| 28 |
+
private float _jumpTimeoutDelta;
|
| 29 |
+
private const float _terminalVelocity = 53.0f;
|
| 30 |
+
|
| 31 |
+
[Space(10)]
|
| 32 |
+
public float JumpTimeout = 0.1f;
|
| 33 |
+
public float FallTimeout = 0.15f;
|
| 34 |
+
|
| 35 |
+
private CharacterController controller;
|
| 36 |
+
private StarterAssetsInputs input;
|
| 37 |
+
|
| 38 |
+
private Vector3 velocity;
|
| 39 |
+
private float cameraPitch = 0f;
|
| 40 |
+
bool canMove = true;
|
| 41 |
+
|
| 42 |
+
private void Awake()
|
| 43 |
+
{
|
| 44 |
+
controller = GetComponent<CharacterController>();
|
| 45 |
+
input = GetComponent<StarterAssetsInputs>();
|
| 46 |
+
}
|
| 47 |
+
|
| 48 |
+
void Start()
|
| 49 |
+
{
|
| 50 |
+
_jumpTimeoutDelta = JumpTimeout;
|
| 51 |
+
_fallTimeoutDelta = FallTimeout;
|
| 52 |
+
}
|
| 53 |
+
|
| 54 |
+
private void OnDrawGizmos()
|
| 55 |
+
{
|
| 56 |
+
if (!Application.isPlaying) return;
|
| 57 |
+
|
| 58 |
+
Gizmos.color = isGrounded ? Color.green : Color.red;
|
| 59 |
+
|
| 60 |
+
Vector3 checkPosition = transform.position + Vector3.down * (controller.height / 2f) + controller.center;
|
| 61 |
+
Gizmos.DrawWireSphere(checkPosition, groundCheckRadius);
|
| 62 |
+
}
|
| 63 |
+
|
| 64 |
+
private void Update()
|
| 65 |
+
{
|
| 66 |
+
GroundedCheck();
|
| 67 |
+
JumpAndGravity();
|
| 68 |
+
if (!canMove)
|
| 69 |
+
return;
|
| 70 |
+
Move();
|
| 71 |
+
}
|
| 72 |
+
|
| 73 |
+
private void LateUpdate()
|
| 74 |
+
{
|
| 75 |
+
CameraRotation();
|
| 76 |
+
}
|
| 77 |
+
|
| 78 |
+
private void GroundedCheck()
|
| 79 |
+
{
|
| 80 |
+
Vector3 spherePosition = transform.position + Vector3.down * (controller.height / 2f) + controller.center;
|
| 81 |
+
isGrounded = Physics.CheckSphere(spherePosition, groundCheckRadius, groundLayer, QueryTriggerInteraction.Ignore);
|
| 82 |
+
}
|
| 83 |
+
|
| 84 |
+
private void JumpAndGravity()
|
| 85 |
+
{
|
| 86 |
+
if (isGrounded)
|
| 87 |
+
{
|
| 88 |
+
_fallTimeoutDelta = FallTimeout;
|
| 89 |
+
|
| 90 |
+
if (velocity.y < 0.0f)
|
| 91 |
+
{
|
| 92 |
+
velocity.y = -2f;
|
| 93 |
+
}
|
| 94 |
+
|
| 95 |
+
if (input.jump && _jumpTimeoutDelta <= 0.0f)
|
| 96 |
+
{
|
| 97 |
+
velocity.y = Mathf.Sqrt(jumpHeight * -2f * gravity);
|
| 98 |
+
_jumpTimeoutDelta = JumpTimeout;
|
| 99 |
+
input.jump = false;
|
| 100 |
+
}
|
| 101 |
+
}
|
| 102 |
+
else
|
| 103 |
+
{
|
| 104 |
+
_fallTimeoutDelta -= Time.deltaTime;
|
| 105 |
+
}
|
| 106 |
+
|
| 107 |
+
if (_jumpTimeoutDelta >= 0.0f)
|
| 108 |
+
{
|
| 109 |
+
_jumpTimeoutDelta -= Time.deltaTime;
|
| 110 |
+
}
|
| 111 |
+
|
| 112 |
+
velocity.y = Mathf.Max(velocity.y + gravity * Time.deltaTime, -_terminalVelocity);
|
| 113 |
+
|
| 114 |
+
controller.Move(velocity * Time.deltaTime);
|
| 115 |
+
}
|
| 116 |
+
|
| 117 |
+
|
| 118 |
+
private void Move()
|
| 119 |
+
{
|
| 120 |
+
float speed = input.sprint ? sprintSpeed : (input.crouch ? crouchSpeed : moveSpeed);
|
| 121 |
+
|
| 122 |
+
Vector3 move = (transform.right * input.move.x + transform.forward * input.move.y).normalized;
|
| 123 |
+
controller.Move(move * speed * Time.deltaTime);
|
| 124 |
+
}
|
| 125 |
+
|
| 126 |
+
private void CameraRotation()
|
| 127 |
+
{
|
| 128 |
+
if (input.look.sqrMagnitude >= 0.01f)
|
| 129 |
+
{
|
| 130 |
+
float mouseX = input.look.x * cameraSensitivity * Time.deltaTime;
|
| 131 |
+
float mouseY = input.look.y * cameraSensitivity * Time.deltaTime;
|
| 132 |
+
|
| 133 |
+
cameraPitch -= mouseY;
|
| 134 |
+
cameraPitch = Mathf.Clamp(cameraPitch, -maxCameraAngle, maxCameraAngle);
|
| 135 |
+
cameraTransform.localRotation = Quaternion.Euler(cameraPitch, 0f, 0f);
|
| 136 |
+
|
| 137 |
+
transform.Rotate(Vector3.up * mouseX);
|
| 138 |
+
}
|
| 139 |
+
}
|
| 140 |
+
|
| 141 |
+
public void UnlockMove(bool value) => canMove = value;
|
| 142 |
+
}
|
Scripts/GameManager.cs
ADDED
|
@@ -0,0 +1,101 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
using UnityEngine;
|
| 2 |
+
using UnityEngine.UI;
|
| 3 |
+
using UnityEngine.InputSystem;
|
| 4 |
+
using System.Collections.Generic;
|
| 5 |
+
using UnityEngine.Playables;
|
| 6 |
+
using TMPro;
|
| 7 |
+
|
| 8 |
+
public enum CrabBehavior
|
| 9 |
+
{
|
| 10 |
+
Flee,
|
| 11 |
+
Follow,
|
| 12 |
+
PickingUp,
|
| 13 |
+
DropItem,
|
| 14 |
+
GoTo,
|
| 15 |
+
StandStill,
|
| 16 |
+
Race
|
| 17 |
+
}
|
| 18 |
+
|
| 19 |
+
public class GameManager : MonoBehaviour
|
| 20 |
+
{
|
| 21 |
+
public static GameManager Instance { get; private set; }
|
| 22 |
+
|
| 23 |
+
[System.Serializable]
|
| 24 |
+
public class WordEffect
|
| 25 |
+
{
|
| 26 |
+
public string word;
|
| 27 |
+
public CrabBehavior crabBehavior;
|
| 28 |
+
public GameObject _target;
|
| 29 |
+
public string targetType;
|
| 30 |
+
public bool affectFlee = true;
|
| 31 |
+
public bool affectTarget = true;
|
| 32 |
+
public AudioClip soundword;
|
| 33 |
+
public Sprite wordSprite;
|
| 34 |
+
}
|
| 35 |
+
|
| 36 |
+
private AudioSource audioSource;
|
| 37 |
+
public PlayableDirector timelineToPlay;
|
| 38 |
+
|
| 39 |
+
public List<WordEffect> wordEffectsList = new List<WordEffect>();
|
| 40 |
+
private Dictionary<string, WordEffect> wordEffectsDictionary = new Dictionary<string, WordEffect>();
|
| 41 |
+
public Animator borders;
|
| 42 |
+
|
| 43 |
+
void Awake()
|
| 44 |
+
{
|
| 45 |
+
// Check if the instance already exists
|
| 46 |
+
if (Instance != null && Instance != this)
|
| 47 |
+
{
|
| 48 |
+
//Destroy(gameObject);
|
| 49 |
+
}
|
| 50 |
+
else
|
| 51 |
+
{
|
| 52 |
+
Instance = this;
|
| 53 |
+
//DontDestroyOnLoad(gameObject);
|
| 54 |
+
}
|
| 55 |
+
}
|
| 56 |
+
|
| 57 |
+
|
| 58 |
+
void Start()
|
| 59 |
+
{
|
| 60 |
+
audioSource = GetComponent<AudioSource>();
|
| 61 |
+
|
| 62 |
+
foreach (var effect in wordEffectsList)
|
| 63 |
+
{
|
| 64 |
+
wordEffectsDictionary[effect.word] = effect;
|
| 65 |
+
}
|
| 66 |
+
}
|
| 67 |
+
|
| 68 |
+
public WordEffect GetEffectForWord(string word)
|
| 69 |
+
{
|
| 70 |
+
if (wordEffectsDictionary.TryGetValue(word, out WordEffect effect))
|
| 71 |
+
{
|
| 72 |
+
return effect;
|
| 73 |
+
}
|
| 74 |
+
return null;
|
| 75 |
+
}
|
| 76 |
+
|
| 77 |
+
public void PlaySoundForWord(string word)
|
| 78 |
+
{
|
| 79 |
+
WordEffect effect = GetEffectForWord(word);
|
| 80 |
+
if (effect != null && effect.soundword != null && audioSource != null)
|
| 81 |
+
{
|
| 82 |
+
audioSource.PlayOneShot(effect.soundword);
|
| 83 |
+
}
|
| 84 |
+
}
|
| 85 |
+
|
| 86 |
+
public void OnSliderValueChanged(float value)
|
| 87 |
+
{
|
| 88 |
+
if (Mathf.Approximately(value, 100f)) // Safer float comparison
|
| 89 |
+
{
|
| 90 |
+
if (timelineToPlay != null)
|
| 91 |
+
{
|
| 92 |
+
timelineToPlay.Play();
|
| 93 |
+
}
|
| 94 |
+
else
|
| 95 |
+
{
|
| 96 |
+
Debug.LogWarning("Timeline is not assigned.");
|
| 97 |
+
}
|
| 98 |
+
}
|
| 99 |
+
}
|
| 100 |
+
}
|
| 101 |
+
|
Scripts/InteractHandler.cs
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
using UnityEngine;
|
| 2 |
+
|
| 3 |
+
public class InteractHandler : MonoBehaviour
|
| 4 |
+
{
|
| 5 |
+
[Copyable] public bool interactable = true;
|
| 6 |
+
[TextArea] public string tooltipText = "Press E to interact";
|
| 7 |
+
[Copyable] public Objective ObjectiveProgress;
|
| 8 |
+
[Copyable] public Objective ObjectiveStart;
|
| 9 |
+
|
| 10 |
+
public virtual void InteractLogic()
|
| 11 |
+
{
|
| 12 |
+
if (ObjectiveProgress != null)
|
| 13 |
+
{
|
| 14 |
+
|
| 15 |
+
//npcObjective.currentProgress = npcObjective.goal;
|
| 16 |
+
ObjectiveManager.Instance.UpdateObjectiveProgress(ObjectiveProgress, 1);
|
| 17 |
+
|
| 18 |
+
Debug.Log($"Objective '{ObjectiveProgress.objectiveName}' updated or completed.");
|
| 19 |
+
ObjectiveProgress = null;
|
| 20 |
+
}
|
| 21 |
+
|
| 22 |
+
if (ObjectiveStart != null)
|
| 23 |
+
{
|
| 24 |
+
|
| 25 |
+
//npcObjective.currentProgress = npcObjective.goal;
|
| 26 |
+
ObjectiveManager.Instance.AddObjective(ObjectiveStart, transform);
|
| 27 |
+
|
| 28 |
+
Debug.Log($"Objective '{ObjectiveStart.objectiveName}' started");
|
| 29 |
+
}
|
| 30 |
+
|
| 31 |
+
Debug.Log("Interacted with: " + gameObject.name);
|
| 32 |
+
interactable = false;
|
| 33 |
+
}
|
| 34 |
+
}
|
Scripts/InteractManager.cs
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
using UnityEngine;
|
| 2 |
+
using TMPro;
|
| 3 |
+
|
| 4 |
+
public class InteractManager : MonoBehaviour
|
| 5 |
+
{
|
| 6 |
+
private StarterAssetsInputs _input;
|
| 7 |
+
public TextMeshProUGUI tooltip;
|
| 8 |
+
|
| 9 |
+
private InteractHandler currentHoverTarget;
|
| 10 |
+
[SerializeField] private bool canInteract = false;
|
| 11 |
+
|
| 12 |
+
void Start()
|
| 13 |
+
{
|
| 14 |
+
_input = GetComponent<StarterAssetsInputs>();
|
| 15 |
+
HideToolTip();
|
| 16 |
+
}
|
| 17 |
+
|
| 18 |
+
void Update()
|
| 19 |
+
{
|
| 20 |
+
if (!canInteract) {
|
| 21 |
+
HideToolTip();
|
| 22 |
+
return;
|
| 23 |
+
}
|
| 24 |
+
|
| 25 |
+
Ray ray = new Ray(Camera.main.transform.position, Camera.main.transform.forward);
|
| 26 |
+
RaycastHit hit;
|
| 27 |
+
|
| 28 |
+
if (Physics.Raycast(ray, out hit))
|
| 29 |
+
{
|
| 30 |
+
InteractHandler interactObject = hit.collider.GetComponent<InteractHandler>();
|
| 31 |
+
|
| 32 |
+
if (interactObject != null && interactObject.interactable)
|
| 33 |
+
{
|
| 34 |
+
// Show tooltip if it's a new object
|
| 35 |
+
if (interactObject != currentHoverTarget)
|
| 36 |
+
{
|
| 37 |
+
currentHoverTarget = interactObject;
|
| 38 |
+
ShowToolTip(interactObject.tooltipText);
|
| 39 |
+
}
|
| 40 |
+
|
| 41 |
+
// Interact on key press
|
| 42 |
+
if (_input != null && _input.interact)
|
| 43 |
+
{
|
| 44 |
+
interactObject.InteractLogic();
|
| 45 |
+
}
|
| 46 |
+
|
| 47 |
+
return;
|
| 48 |
+
}
|
| 49 |
+
}
|
| 50 |
+
|
| 51 |
+
if (currentHoverTarget != null)
|
| 52 |
+
{
|
| 53 |
+
currentHoverTarget = null;
|
| 54 |
+
HideToolTip();
|
| 55 |
+
}
|
| 56 |
+
}
|
| 57 |
+
|
| 58 |
+
public void ShowToolTip(string message)
|
| 59 |
+
{
|
| 60 |
+
tooltip.text = message;
|
| 61 |
+
tooltip.gameObject.SetActive(true);
|
| 62 |
+
}
|
| 63 |
+
|
| 64 |
+
public void HideToolTip()
|
| 65 |
+
{
|
| 66 |
+
tooltip.gameObject.SetActive(false);
|
| 67 |
+
}
|
| 68 |
+
|
| 69 |
+
public void UnlockInteract(bool unlock)
|
| 70 |
+
{
|
| 71 |
+
canInteract = unlock;
|
| 72 |
+
}
|
| 73 |
+
}
|
Scripts/LogManager.cs
ADDED
|
@@ -0,0 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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
using System;
|
| 2 |
+
using System.Collections.Generic;
|
| 3 |
+
using System.Linq;
|
| 4 |
+
using UnityEngine;
|
| 5 |
+
using UnityEngine.UI;
|
| 6 |
+
|
| 7 |
+
public class LogManager : MonoBehaviour
|
| 8 |
+
{
|
| 9 |
+
[System.Serializable]
|
| 10 |
+
public class LogEntry
|
| 11 |
+
{
|
| 12 |
+
public string wordOfInterest;
|
| 13 |
+
public string userDefinition;
|
| 14 |
+
}
|
| 15 |
+
|
| 16 |
+
public List<LogEntry> logEntries = new List<LogEntry>();
|
| 17 |
+
public GameObject logPrefab;
|
| 18 |
+
public Transform contentPanel;
|
| 19 |
+
public GameObject logMenu;
|
| 20 |
+
private bool isLogOpen = false;
|
| 21 |
+
private InteractManager interactMan;
|
| 22 |
+
|
| 23 |
+
private StarterAssetsInputs input;
|
| 24 |
+
public ScrollRect scrollRect;
|
| 25 |
+
private CrabInterface crabInterface;
|
| 26 |
+
public Animator scrollArea;
|
| 27 |
+
|
| 28 |
+
[Header("Audio")]
|
| 29 |
+
public AudioClip openLogSound;
|
| 30 |
+
public AudioClip closeLogSound;
|
| 31 |
+
public AudioClip confirmSound;
|
| 32 |
+
public AudioClip clearSound;
|
| 33 |
+
private AudioSource audioSource;
|
| 34 |
+
|
| 35 |
+
[Copyable] public bool canOpenLog = false;
|
| 36 |
+
|
| 37 |
+
void Start()
|
| 38 |
+
{
|
| 39 |
+
UpdateLog();
|
| 40 |
+
interactMan = GetComponent<InteractManager>();
|
| 41 |
+
input = GetComponent<StarterAssetsInputs>();
|
| 42 |
+
logMenu.SetActive(false);
|
| 43 |
+
|
| 44 |
+
audioSource = GetComponent<AudioSource>();
|
| 45 |
+
if (audioSource == null)
|
| 46 |
+
{
|
| 47 |
+
audioSource = gameObject.AddComponent<AudioSource>();
|
| 48 |
+
audioSource.playOnAwake = false;
|
| 49 |
+
}
|
| 50 |
+
}
|
| 51 |
+
|
| 52 |
+
void Update()
|
| 53 |
+
{
|
| 54 |
+
if (!canOpenLog)
|
| 55 |
+
{
|
| 56 |
+
return;
|
| 57 |
+
}
|
| 58 |
+
|
| 59 |
+
if (input.log)
|
| 60 |
+
{
|
| 61 |
+
ToggleLogMenu(!isLogOpen);
|
| 62 |
+
input.log = false;
|
| 63 |
+
}
|
| 64 |
+
}
|
| 65 |
+
|
| 66 |
+
public void SetCrabInterface(CrabInterface newCrabInterface)
|
| 67 |
+
{
|
| 68 |
+
crabInterface = newCrabInterface;
|
| 69 |
+
}
|
| 70 |
+
|
| 71 |
+
public void ToggleLogMenu(bool open)
|
| 72 |
+
{
|
| 73 |
+
isLogOpen = open;
|
| 74 |
+
logMenu.SetActive(isLogOpen);
|
| 75 |
+
AudioManager.Instance.ToggleRadioEQ(isLogOpen);
|
| 76 |
+
if (audioSource != null)
|
| 77 |
+
{
|
| 78 |
+
if (isLogOpen && openLogSound != null)
|
| 79 |
+
{
|
| 80 |
+
audioSource.PlayOneShot(openLogSound);
|
| 81 |
+
}
|
| 82 |
+
else if (!isLogOpen && closeLogSound != null)
|
| 83 |
+
{
|
| 84 |
+
audioSource.PlayOneShot(closeLogSound);
|
| 85 |
+
}
|
| 86 |
+
}
|
| 87 |
+
|
| 88 |
+
if (isLogOpen)
|
| 89 |
+
{
|
| 90 |
+
AudioManager.Instance.ToggleRadioEQ(isLogOpen);
|
| 91 |
+
Time.timeScale = 0f;
|
| 92 |
+
input.SetCursorState(false);
|
| 93 |
+
interactMan.UnlockInteract(false);
|
| 94 |
+
scrollArea.Play("EnterScrollArea");
|
| 95 |
+
if (scrollRect != null)
|
| 96 |
+
{
|
| 97 |
+
scrollRect.verticalNormalizedPosition = 1f;
|
| 98 |
+
}
|
| 99 |
+
}
|
| 100 |
+
else
|
| 101 |
+
{
|
| 102 |
+
if (crabInterface != null)
|
| 103 |
+
Destroy(crabInterface.gameObject);
|
| 104 |
+
|
| 105 |
+
Time.timeScale = 1f;
|
| 106 |
+
interactMan.UnlockInteract(true);
|
| 107 |
+
input.SetCursorState(true);
|
| 108 |
+
}
|
| 109 |
+
}
|
| 110 |
+
|
| 111 |
+
public void AddWord(string newWord)
|
| 112 |
+
{
|
| 113 |
+
interactMan = GetComponent<InteractManager>();
|
| 114 |
+
input = GetComponent<StarterAssetsInputs>();
|
| 115 |
+
newWord = newWord.TrimEnd('!', '.', ',', '?', ';', ':').ToLower();
|
| 116 |
+
newWord = Char.ToUpper(newWord[0]) + newWord.Substring(1);
|
| 117 |
+
|
| 118 |
+
if (logEntries.Exists(entry => entry.wordOfInterest == newWord))
|
| 119 |
+
return;
|
| 120 |
+
|
| 121 |
+
logEntries.Add(new LogEntry { wordOfInterest = newWord, userDefinition = "" });
|
| 122 |
+
UpdateLog();
|
| 123 |
+
}
|
| 124 |
+
|
| 125 |
+
|
| 126 |
+
public void UpdateLog()
|
| 127 |
+
{
|
| 128 |
+
foreach (Transform child in contentPanel)
|
| 129 |
+
{
|
| 130 |
+
Destroy(child.gameObject);
|
| 131 |
+
}
|
| 132 |
+
|
| 133 |
+
foreach (var entry in logEntries.OrderBy(e => e.wordOfInterest))
|
| 134 |
+
{
|
| 135 |
+
GameObject logInstance = Instantiate(logPrefab, contentPanel);
|
| 136 |
+
Button button = logInstance.GetComponent<Button>();
|
| 137 |
+
LogUI logUI = logInstance.GetComponent<LogUI>();
|
| 138 |
+
logUI.Setup(entry.wordOfInterest, entry.userDefinition, this);
|
| 139 |
+
button.onClick.AddListener(() => OnWordClicked(entry));
|
| 140 |
+
}
|
| 141 |
+
}
|
| 142 |
+
|
| 143 |
+
private void OnWordClicked(LogEntry entry)
|
| 144 |
+
{
|
| 145 |
+
if (crabInterface != null)
|
| 146 |
+
{
|
| 147 |
+
crabInterface.AddWordToBoard(entry.wordOfInterest);
|
| 148 |
+
}
|
| 149 |
+
|
| 150 |
+
if (GameManager.Instance != null)
|
| 151 |
+
{
|
| 152 |
+
GameManager.Instance.PlaySoundForWord(entry.wordOfInterest);
|
| 153 |
+
}
|
| 154 |
+
}
|
| 155 |
+
|
| 156 |
+
public void UpdateUserDefinition(string word, string newDefinition)
|
| 157 |
+
{
|
| 158 |
+
LogEntry entry = logEntries.Find(e => e.wordOfInterest == word);
|
| 159 |
+
if (entry != null)
|
| 160 |
+
{
|
| 161 |
+
entry.userDefinition = newDefinition;
|
| 162 |
+
}
|
| 163 |
+
}
|
| 164 |
+
|
| 165 |
+
public void StartLogManager()
|
| 166 |
+
{
|
| 167 |
+
|
| 168 |
+
}
|
| 169 |
+
|
| 170 |
+
public void UnlockLog(bool unlock)
|
| 171 |
+
{
|
| 172 |
+
canOpenLog = unlock;
|
| 173 |
+
}
|
| 174 |
+
}
|
Scripts/LogUI.cs
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
using UnityEngine;
|
| 2 |
+
using UnityEngine.UI;
|
| 3 |
+
using TMPro;
|
| 4 |
+
|
| 5 |
+
public class LogUI : MonoBehaviour
|
| 6 |
+
{
|
| 7 |
+
public TextMeshProUGUI wordText;
|
| 8 |
+
public TMP_InputField definitionInput;
|
| 9 |
+
private LogManager manager;
|
| 10 |
+
private string word;
|
| 11 |
+
|
| 12 |
+
public void Setup(string word, string definition, LogManager manager)
|
| 13 |
+
{
|
| 14 |
+
this.word = word;
|
| 15 |
+
this.manager = manager;
|
| 16 |
+
wordText.text = word;
|
| 17 |
+
definitionInput.text = definition;
|
| 18 |
+
|
| 19 |
+
definitionInput.onValueChanged.AddListener(UpdateDefinition);
|
| 20 |
+
}
|
| 21 |
+
|
| 22 |
+
private void UpdateDefinition(string userInput)
|
| 23 |
+
{
|
| 24 |
+
manager.UpdateUserDefinition(word, userInput);
|
| 25 |
+
}
|
| 26 |
+
}
|
Scripts/PickupObject.cs
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
using UnityEngine;
|
| 2 |
+
|
| 3 |
+
public class PickupObject : MonoBehaviour
|
| 4 |
+
{
|
| 5 |
+
[Header("Pickup Settings")]
|
| 6 |
+
public float moveSpeed = 10f; // Speed at which the object moves
|
| 7 |
+
public Vector3 holdOffset = new Vector3(0, 0, 1.5f); // Offset in front of the camera
|
| 8 |
+
|
| 9 |
+
private Transform cameraTransform; // Player's camera transform
|
| 10 |
+
private Vector3 originalPosition; // Original position of the object
|
| 11 |
+
private Quaternion originalRotation; // Original rotation of the object
|
| 12 |
+
private bool isHolding = false; // Whether the object is currently in front of the camera
|
| 13 |
+
|
| 14 |
+
void Start()
|
| 15 |
+
{
|
| 16 |
+
// Find the player's camera (assumes it's tagged as "MainCamera")
|
| 17 |
+
cameraTransform = Camera.main.transform;
|
| 18 |
+
|
| 19 |
+
// Save the original position and rotation of the object
|
| 20 |
+
originalPosition = transform.position;
|
| 21 |
+
originalRotation = transform.rotation;
|
| 22 |
+
}
|
| 23 |
+
|
| 24 |
+
void Update()
|
| 25 |
+
{
|
| 26 |
+
// Smoothly move the object to its target position
|
| 27 |
+
if (isHolding)
|
| 28 |
+
{
|
| 29 |
+
// Move the object in front of the camera
|
| 30 |
+
Vector3 targetPosition = cameraTransform.position + cameraTransform.forward * holdOffset.z + cameraTransform.up * holdOffset.y;
|
| 31 |
+
Quaternion targetRotation = Quaternion.LookRotation(cameraTransform.forward, cameraTransform.up);
|
| 32 |
+
|
| 33 |
+
transform.position = Vector3.Lerp(transform.position, targetPosition, moveSpeed * Time.deltaTime);
|
| 34 |
+
transform.rotation = Quaternion.Lerp(transform.rotation, targetRotation, moveSpeed * Time.deltaTime);
|
| 35 |
+
}
|
| 36 |
+
else
|
| 37 |
+
{
|
| 38 |
+
// Return the object to its original position
|
| 39 |
+
transform.position = Vector3.Lerp(transform.position, originalPosition, moveSpeed * Time.deltaTime);
|
| 40 |
+
transform.rotation = Quaternion.Lerp(transform.rotation, originalRotation, moveSpeed * Time.deltaTime);
|
| 41 |
+
}
|
| 42 |
+
}
|
| 43 |
+
|
| 44 |
+
// Toggle the object's hold state
|
| 45 |
+
public void ToggleHold()
|
| 46 |
+
{
|
| 47 |
+
isHolding = !isHolding;
|
| 48 |
+
}
|
| 49 |
+
}
|
Scripts/Player.cs
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
using UnityEngine;
|
| 2 |
+
|
| 3 |
+
public class Player : MonoBehaviour
|
| 4 |
+
{
|
| 5 |
+
public static Player Instance;
|
| 6 |
+
|
| 7 |
+
void Awake()
|
| 8 |
+
{
|
| 9 |
+
if (Instance == null)
|
| 10 |
+
Instance = this;
|
| 11 |
+
else
|
| 12 |
+
Destroy(gameObject);
|
| 13 |
+
}
|
| 14 |
+
}
|
Scripts/ReloadScene.cs
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
using UnityEngine;
|
| 2 |
+
using UnityEngine.SceneManagement;
|
| 3 |
+
|
| 4 |
+
public class ReloadScene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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
using UnityEngine;
|
| 2 |
+
using UnityEngine.InputSystem;
|
| 3 |
+
|
| 4 |
+
|
| 5 |
+
public class StarterAssetsInputs : MonoBehaviour
|
| 6 |
+
{
|
| 7 |
+
[Header("Character Input Values")]
|
| 8 |
+
public Vector2 move, look;
|
| 9 |
+
public bool jump, sprint, crouch, attack, aim, interact, drop, log;
|
| 10 |
+
public bool equip1, equip2, equip3;
|
| 11 |
+
public bool toggleEquip;
|
| 12 |
+
public float cycleInput;
|
| 13 |
+
|
| 14 |
+
[Header("Movement Settings")]
|
| 15 |
+
public bool analogMovement;
|
| 16 |
+
|
| 17 |
+
[Header("Mouse Cursor Settings")]
|
| 18 |
+
public bool cursorLocked = true;
|
| 19 |
+
public bool cursorInputForLook = true;
|
| 20 |
+
|
| 21 |
+
//STANDARD MOVEMENT
|
| 22 |
+
|
| 23 |
+
void Start() {
|
| 24 |
+
SetCursorState(true);
|
| 25 |
+
}
|
| 26 |
+
|
| 27 |
+
public void OnMove(InputValue value)
|
| 28 |
+
{
|
| 29 |
+
MoveInput(value.Get<Vector2>());
|
| 30 |
+
}
|
| 31 |
+
|
| 32 |
+
public void OnLook(InputValue value)
|
| 33 |
+
{
|
| 34 |
+
if(cursorInputForLook)
|
| 35 |
+
{
|
| 36 |
+
LookInput(value.Get<Vector2>());
|
| 37 |
+
}
|
| 38 |
+
}
|
| 39 |
+
|
| 40 |
+
//SPECIAL MOVEMENT
|
| 41 |
+
|
| 42 |
+
public void OnJump(InputValue value)
|
| 43 |
+
{
|
| 44 |
+
JumpInput(value.isPressed);
|
| 45 |
+
}
|
| 46 |
+
|
| 47 |
+
public void OnSprint(InputValue value)
|
| 48 |
+
{
|
| 49 |
+
SprintInput(value.isPressed);
|
| 50 |
+
}
|
| 51 |
+
|
| 52 |
+
public void OnCrouch(InputValue value)
|
| 53 |
+
{
|
| 54 |
+
CrouchInput(value.isPressed);
|
| 55 |
+
}
|
| 56 |
+
|
| 57 |
+
//ATTACK
|
| 58 |
+
|
| 59 |
+
public void OnAttack(InputValue value)
|
| 60 |
+
{
|
| 61 |
+
AttackInput(value.isPressed);
|
| 62 |
+
}
|
| 63 |
+
|
| 64 |
+
public void OnAim(InputValue value)
|
| 65 |
+
{
|
| 66 |
+
AimInput(value.isPressed);
|
| 67 |
+
}
|
| 68 |
+
|
| 69 |
+
public void OnDrop(InputValue value)
|
| 70 |
+
{
|
| 71 |
+
DropInput(value.isPressed);
|
| 72 |
+
}
|
| 73 |
+
|
| 74 |
+
public void OnLog(InputValue value)
|
| 75 |
+
{
|
| 76 |
+
LogInput(value.isPressed);
|
| 77 |
+
}
|
| 78 |
+
|
| 79 |
+
|
| 80 |
+
// INTERACT
|
| 81 |
+
|
| 82 |
+
public void OnInteract(InputValue value)
|
| 83 |
+
{
|
| 84 |
+
InteractInput(value.isPressed);
|
| 85 |
+
}
|
| 86 |
+
|
| 87 |
+
public void OnCycle(InputValue value)
|
| 88 |
+
{
|
| 89 |
+
Vector2 scrollValue = value.Get<Vector2>();
|
| 90 |
+
cycleInput = scrollValue.y;
|
| 91 |
+
|
| 92 |
+
if (cycleInput > 0)
|
| 93 |
+
{
|
| 94 |
+
CycleForward();
|
| 95 |
+
}
|
| 96 |
+
else if (cycleInput < 0)
|
| 97 |
+
{
|
| 98 |
+
CycleBackward();
|
| 99 |
+
}
|
| 100 |
+
}
|
| 101 |
+
|
| 102 |
+
public void CycleForward()
|
| 103 |
+
{
|
| 104 |
+
if (equip1)
|
| 105 |
+
{
|
| 106 |
+
equip1 = false;
|
| 107 |
+
equip2 = true;
|
| 108 |
+
equip3 = false;
|
| 109 |
+
}
|
| 110 |
+
else if (equip2)
|
| 111 |
+
{
|
| 112 |
+
equip2 = false;
|
| 113 |
+
equip1 = true;
|
| 114 |
+
equip3 = false;
|
| 115 |
+
}
|
| 116 |
+
else
|
| 117 |
+
{
|
| 118 |
+
equip1 = true;
|
| 119 |
+
equip3 = false;
|
| 120 |
+
}
|
| 121 |
+
}
|
| 122 |
+
|
| 123 |
+
public void CycleBackward()
|
| 124 |
+
{
|
| 125 |
+
CycleForward();
|
| 126 |
+
}
|
| 127 |
+
|
| 128 |
+
public void OnToggleEquip(InputValue value)
|
| 129 |
+
{
|
| 130 |
+
ToggleEquipInput(value.isPressed);
|
| 131 |
+
|
| 132 |
+
if (value.isPressed)
|
| 133 |
+
{
|
| 134 |
+
CycleForward();
|
| 135 |
+
}
|
| 136 |
+
}
|
| 137 |
+
|
| 138 |
+
//EQUIP
|
| 139 |
+
|
| 140 |
+
public void OnEquip1(InputValue value)
|
| 141 |
+
{
|
| 142 |
+
EquipInput(1, value.isPressed);
|
| 143 |
+
}
|
| 144 |
+
|
| 145 |
+
public void OnEquip2(InputValue value)
|
| 146 |
+
{
|
| 147 |
+
EquipInput(2, value.isPressed);
|
| 148 |
+
}
|
| 149 |
+
|
| 150 |
+
public void OnEquip3(InputValue value)
|
| 151 |
+
{
|
| 152 |
+
equip1 = false;
|
| 153 |
+
equip2 = false;
|
| 154 |
+
EquipInput(3, value.isPressed);
|
| 155 |
+
}
|
| 156 |
+
|
| 157 |
+
//INPUT
|
| 158 |
+
|
| 159 |
+
public void MoveInput(Vector2 newMoveDirection)
|
| 160 |
+
{
|
| 161 |
+
move = newMoveDirection;
|
| 162 |
+
}
|
| 163 |
+
|
| 164 |
+
public void LookInput(Vector2 newLookDirection)
|
| 165 |
+
{
|
| 166 |
+
look = newLookDirection;
|
| 167 |
+
}
|
| 168 |
+
|
| 169 |
+
public void JumpInput(bool newJumpState)
|
| 170 |
+
{
|
| 171 |
+
jump = newJumpState;
|
| 172 |
+
}
|
| 173 |
+
|
| 174 |
+
public void SprintInput(bool newSprintState)
|
| 175 |
+
{
|
| 176 |
+
sprint = newSprintState;
|
| 177 |
+
}
|
| 178 |
+
|
| 179 |
+
public void CrouchInput(bool newCrouchState)
|
| 180 |
+
{
|
| 181 |
+
crouch = newCrouchState;
|
| 182 |
+
}
|
| 183 |
+
|
| 184 |
+
public void AttackInput(bool newAttackState)
|
| 185 |
+
{
|
| 186 |
+
attack = newAttackState;
|
| 187 |
+
}
|
| 188 |
+
|
| 189 |
+
public void AimInput(bool newAimState)
|
| 190 |
+
{
|
| 191 |
+
aim = newAimState;
|
| 192 |
+
}
|
| 193 |
+
|
| 194 |
+
public void DropInput(bool newDropState)
|
| 195 |
+
{
|
| 196 |
+
drop = newDropState;
|
| 197 |
+
}
|
| 198 |
+
|
| 199 |
+
public void LogInput(bool newLogState)
|
| 200 |
+
{
|
| 201 |
+
log = newLogState;
|
| 202 |
+
}
|
| 203 |
+
|
| 204 |
+
public void InteractInput(bool newInteractState)
|
| 205 |
+
{
|
| 206 |
+
interact = newInteractState;
|
| 207 |
+
}
|
| 208 |
+
|
| 209 |
+
public void CycleInput(float newCycleState)
|
| 210 |
+
{
|
| 211 |
+
cycleInput = newCycleState;
|
| 212 |
+
}
|
| 213 |
+
|
| 214 |
+
public void ToggleEquipInput(bool newToggleEquipState)
|
| 215 |
+
{
|
| 216 |
+
toggleEquip = newToggleEquipState;
|
| 217 |
+
}
|
| 218 |
+
|
| 219 |
+
public void EquipInput(int equipSlot, bool newState)
|
| 220 |
+
{
|
| 221 |
+
switch (equipSlot)
|
| 222 |
+
{
|
| 223 |
+
case 1:
|
| 224 |
+
equip1 = newState;
|
| 225 |
+
break;
|
| 226 |
+
case 2:
|
| 227 |
+
equip2 = newState;
|
| 228 |
+
break;
|
| 229 |
+
case 3:
|
| 230 |
+
equip3 = newState;
|
| 231 |
+
break;
|
| 232 |
+
default:
|
| 233 |
+
Debug.LogError("Invalid equipment slot");
|
| 234 |
+
break;
|
| 235 |
+
}
|
| 236 |
+
}
|
| 237 |
+
|
| 238 |
+
private void OnApplicationFocus(bool hasFocus)
|
| 239 |
+
{
|
| 240 |
+
SetCursorState(cursorLocked);
|
| 241 |
+
}
|
| 242 |
+
|
| 243 |
+
public void SetCursorState(bool newState)
|
| 244 |
+
{
|
| 245 |
+
Cursor.lockState = newState ? CursorLockMode.Locked : CursorLockMode.None;
|
| 246 |
+
}
|
| 247 |
+
}
|
Scripts/UICrabAnimator.cs
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
using UnityEngine;
|
| 2 |
+
|
| 3 |
+
public class UICrabAnimator : MonoBehaviour
|
| 4 |
+
{
|
| 5 |
+
// Start is called once before the first execution of Update after the MonoBehaviour is created
|
| 6 |
+
void Start()
|
| 7 |
+
{
|
| 8 |
+
|
| 9 |
+
}
|
| 10 |
+
|
| 11 |
+
// Update is called once per frame
|
| 12 |
+
void Update()
|
| 13 |
+
{
|
| 14 |
+
|
| 15 |
+
}
|
| 16 |
+
}
|