added test light switches and hold progress circle

This commit is contained in:
janis
2022-02-15 17:50:57 +01:00
parent c485401c58
commit 7872a35be1
341 changed files with 27344 additions and 9134 deletions

View File

@@ -1,10 +1,15 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using TMPro;
using UnityEngine.UI;
public class PlayerInteraction : MonoBehaviour
{
public TMPro.TextMeshProUGUI interactionText;
[SerializeField]
TextMeshProUGUI interactionText;
[SerializeField]
Image interactionProgressImg;
void Update()
{
@@ -21,15 +26,22 @@ public class PlayerInteraction : MonoBehaviour
HandleInteraction(interactable);
successfulHit = true;
HandleInteractionText(interactable);
HandleInteractionProgress(interactable);
}
}
if (!successfulHit)
{
interactionText.text = "";
interactionProgressImg.fillAmount = 0;
}
}
void HandleInteractionProgress(Interactable interactable)
{
interactionProgressImg.fillAmount = interactable.GetHoldTime() / interactable.GetHoldDuration();
}
void HandleInteractionText(Interactable interactable)
{
@@ -46,13 +58,13 @@ public class PlayerInteraction : MonoBehaviour
switch (interactable.interactionType)
{
case Interactable.InteractionType.Click:
if (Input.GetButtonDown("Interact"))
if (Input.GetButtonDown("Interact") && interactable.isInRange())
{
interactable.Interact();
}
break;
case Interactable.InteractionType.Hold:
if (Input.GetButton("Interact"))
if (Input.GetButton("Interact") && interactable.isInRange())
{
interactable.IncreaseHoldTime();
@@ -69,8 +81,8 @@ public class PlayerInteraction : MonoBehaviour
break;
case Interactable.InteractionType.Harvest:
Harvestable harvestable = interactable.GetComponent<Harvestable>();
Debug.Log(harvestable.GetHarvestTimeLeft());
if (Input.GetButton("Interact"))
if (Input.GetButton("Interact") && interactable.isInRange())
{
harvestable.IncreaseHarvestTime();