mirror of
https://github.com/DerTyp7/example-top-down-unity.git
synced 2025-10-30 04:47:09 +01:00
added test light switches and hold progress circle
This commit is contained in:
@@ -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();
|
||||
|
||||
|
||||
22
Assets/Scripts/TestLight.cs
Normal file
22
Assets/Scripts/TestLight.cs
Normal 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);
|
||||
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/TestLight.cs.meta
Normal file
11
Assets/Scripts/TestLight.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9cfe123230b3a464da8006f1a53a48e8
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -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";
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user