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();

View File

@@ -0,0 +1,22 @@
using UnityEngine;
using UnityEngine.Rendering.Universal;
public class TestLight : Interactable
{
[Header("Test Light Properties")]
[SerializeField] Color color;
[SerializeField] Light2D globalLight;
public override string GetDescription()
{
if (isInRange())
return "Turn Light " + gameObject.name;
else
return "Light switch not in range";
}
public override void Interact()
{
globalLight.color = color;
Debug.Log("Color set to " + gameObject.name);
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 9cfe123230b3a464da8006f1a53a48e8
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -1,5 +1,3 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class TreeInteraction : Harvestable
@@ -8,7 +6,7 @@ public class TreeInteraction : Harvestable
public override string GetDescription()
{
if (isInRange())
return "Baum muss schreien";
return "Baum muss weg";
else
return "Tree is not in range";
}