ProjetPatate/Assets/Scripts/Workshop.cs

48 lines
1.7 KiB
C#
Raw Normal View History

2020-12-05 13:38:13 +01:00
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
2020-12-10 13:51:16 +01:00
//Define the behavior of a workshop
2020-12-05 13:38:13 +01:00
[RequireComponent(typeof(Collider2D))]
2020-12-10 13:51:16 +01:00
public abstract class Workshop : MonoBehaviour, IUsable
2020-12-05 13:38:13 +01:00
{
2020-12-10 13:51:16 +01:00
protected GameObject currentMug = null; //Mug currently stocked in workshop
2020-12-05 13:38:13 +01:00
public float prepTime = 2.0f; //Time for preparation of product
protected float prepTimer= 0.0f;
public UITimer UIPrepTimer = null; //Script of the UI display
protected bool playerInteracting = false; //Wether the player is interacting w/ the workshop
// bool playerInteractFrame = false; //Wether the player used the workshop in the current frame
2020-12-05 15:22:00 +01:00
//Handle objects interactions w/ Workshop
2020-12-05 13:38:13 +01:00
//Return wether the object is taken from tavernkeeper
public abstract bool use(GameObject userObject);
2020-12-05 13:38:13 +01:00
// Start is called before the first frame update
void Start()
{
2020-12-07 17:22:30 +01:00
if(gameObject.layer != LayerMask.NameToLayer("Interactions"))
Debug.LogWarning(gameObject.name+" layer should be set to 'Interactions' to work properly");
2020-12-10 11:57:23 +01:00
if(gameObject.tag != "Usable")
Debug.LogWarning(gameObject.name+" tag should be set to 'Usable' to work properly");
if(UIPrepTimer is null)
Debug.LogWarning(gameObject.name+" doesn't have a UIPrepTimer set");
else
UIPrepTimer.gameObject.SetActive(false);
}
void LateUpdate()
{
if(playerInteracting)
{
if(prepTimer<prepTime) //Update UI Prep timer
{
prepTimer+=Time.deltaTime;
UIPrepTimer.SetValue(prepTimer/prepTime);
}
playerInteracting=false; //Reset interaction indicator for next frame
}
2020-12-05 13:38:13 +01:00
}
}