reworked interactions, fixed health depleting from testing

This commit is contained in:
TAASONI3
2023-12-29 17:29:03 +01:00
parent 661aa6704b
commit f57389e8a4
42 changed files with 325 additions and 105 deletions

View File

@@ -6,6 +6,7 @@ using UnityEngine.EventSystems;
using UnityEngine.InputSystem;
using UnityEngine.UI;
using Assets.Scripts.Player;
using Assets.Scripts.InteractableObjects;
public class Controls : MonoBehaviour
{
@@ -141,22 +142,17 @@ public class Controls : MonoBehaviour
fight.GetComponent<Fight>().startFight(worldGen.GetComponent<WorldGenerator>().getCurrentTile(), target, player);
break;
case "Tree":
StartCoroutine(playAnimation(target, "Chopping"));
player.GetComponent<PlayerGameObject>().getPlayer().getStat("TreeCount").changeAmount(1);
GameObject.Find("Inventory").GetComponent<Inventory>().addItem(new Item("Wood"));
break;
case "Stone":
StartCoroutine(playAnimation(target, "Mining"));
GameObject.Find("Inventory").GetComponent<Inventory>().addItem(new Item("Rock"));
break;
case "NPC":
target.GetComponent<NPC>().interact();
break;
case "Door":
target.GetComponent<Door>().interact();
break;
case "Chest":
target.GetComponent<Chest>().interact();
break;
case "Ore":
if (target.name.ToLower().Contains("iron"))
@@ -176,44 +172,13 @@ public class Controls : MonoBehaviour
GameObject.Find("Inventory").GetComponent<Inventory>().addItem(new Item("Tin ore"));
}
player.GetComponent<PlayerGameObject>().getPlayer().getStat("OreCount").changeAmount(1);
StartCoroutine(playAnimation(target, "Mining"));
break;
}
target.GetComponent<InteractableObject>().OnInteraction(player);
}
}
}
IEnumerator playParticle(GameObject target)
{
Vector3 playerPos = player.transform.position;
playerPos.y = target.transform.position.y;
Quaternion newRotation = Quaternion.LookRotation(playerPos - target.transform.position, target.transform.TransformDirection(Vector3.up));
ParticleSystem particleSystem = target.GetComponent<ParticleSystem>();
ParticleSystem.ShapeModule shape = particleSystem.shape;
shape.rotation = newRotation.eulerAngles;
particleSystem.Play();
yield return new WaitUntil(() => !particleSystem.isPlaying);
Destroy(target);
}
IEnumerator playAnimation(GameObject target, string key)
{
player.GetComponent<Animator>().Play(key);
Animator animator = player.GetComponent<Animator>();
AnimationClip[] clips = animator.runtimeAnimatorController.animationClips;
float length = 0;
foreach (AnimationClip clip in clips)
{
if (clip.name.ToLower() == key.ToLower())
{
length = clip.length;
break;
}
}
yield return new WaitForSeconds(length);
Destroy(target);
}
public void OnInventory()
{
uihandler.switchInventory();