2023-03-14 00:59:59 +01:00
|
|
|
using System.Collections;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using UnityEngine;
|
|
|
|
using TMPro;
|
|
|
|
using UnityEngine.UI;
|
|
|
|
|
|
|
|
|
|
|
|
[RequireComponent(typeof(Collider))]
|
|
|
|
[RequireComponent(typeof(Rigidbody))]
|
2023-03-21 19:49:47 +01:00
|
|
|
public abstract class InteractableItem : CarryableItem
|
2023-03-14 00:59:59 +01:00
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
[SerializeField]
|
|
|
|
private Canvas interactionCanvas;
|
|
|
|
private TMP_Text[] interaction_texts;
|
|
|
|
private Image[] interaction_images;
|
|
|
|
protected float target_alpha = 0;
|
|
|
|
[SerializeField]
|
|
|
|
protected bool canPickup = false;
|
|
|
|
protected bool isEnabled = false;
|
|
|
|
|
|
|
|
public bool CanPickup { get { return canPickup; } }
|
|
|
|
public bool IsEnabled { get { return isEnabled; } }
|
|
|
|
|
|
|
|
public void Enable()
|
|
|
|
{
|
2023-04-03 17:02:11 +02:00
|
|
|
//print("Enabled!");
|
2023-03-14 00:59:59 +01:00
|
|
|
interactionCanvas.transform.LookAt((GameObject.FindGameObjectWithTag("MainCamera").transform.position));
|
|
|
|
interactionCanvas.transform.Rotate(0, 180, 0);
|
|
|
|
target_alpha = 1;
|
|
|
|
isEnabled = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void Disable()
|
|
|
|
{
|
2023-04-03 17:02:11 +02:00
|
|
|
//print("Disabled!");
|
2023-03-14 00:59:59 +01:00
|
|
|
target_alpha = 0;
|
|
|
|
isEnabled = true;
|
|
|
|
}
|
2023-03-21 19:49:47 +01:00
|
|
|
public abstract bool Interact();
|
|
|
|
public abstract bool Interact(ref Inventory inventory,ref HeavyInteractableItem heavyInvent);
|
|
|
|
|
2023-03-14 00:59:59 +01:00
|
|
|
protected void BaseAwake()
|
|
|
|
{
|
|
|
|
interaction_texts = interactionCanvas.GetComponentsInChildren<TMP_Text>();
|
|
|
|
interaction_images = interactionCanvas.GetComponentsInChildren<Image>();
|
|
|
|
foreach (TMP_Text text in interaction_texts)
|
|
|
|
{
|
|
|
|
text.color = new Color(text.color.r, text.color.g, text.color.b, 0);
|
|
|
|
}
|
|
|
|
foreach (Image image in interaction_images)
|
|
|
|
{
|
|
|
|
image.color = new Color(image.color.r, image.color.g, image.color.b, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
protected void BaseFixedUpdate()
|
|
|
|
{
|
|
|
|
foreach (TMP_Text text in interaction_texts)
|
|
|
|
{
|
|
|
|
text.color = Color.Lerp(new Color(text.color.r, text.color.g, text.color.b, text.color.a), new Color(text.color.r, text.color.g, text.color.b, target_alpha), 10 * Time.deltaTime);
|
|
|
|
}
|
|
|
|
foreach (Image image in interaction_images)
|
|
|
|
{
|
|
|
|
image.color = Color.Lerp(new Color(image.color.r, image.color.g, image.color.b, image.color.a), new Color(image.color.r, image.color.g, image.color.b, target_alpha), 10 * Time.deltaTime);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void Awake()
|
|
|
|
{
|
|
|
|
BaseAwake();
|
|
|
|
}
|
|
|
|
private void FixedUpdate()
|
|
|
|
{
|
|
|
|
BaseFixedUpdate();
|
|
|
|
}
|
|
|
|
}
|