ProjetPatate/Assets/Scripts/Client_controller.cs

78 lines
2.4 KiB
C#
Raw Normal View History

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
2020-12-05 15:22:00 +01:00
//Define the behavior of a client
[RequireComponent(typeof(Collider2D))]
public class Client_controller : MonoBehaviour
{
public float consumeTime = 3.0f; //Time to consume currentMug
public float waitingTime = 10.0f; //Patience after ordering
2020-12-07 15:40:34 +01:00
2020-12-05 15:22:00 +01:00
GameObject currentMug = null; //Mug currently held by the client
2020-12-07 15:40:34 +01:00
float consumeTimer;
2020-12-05 15:22:00 +01:00
//Handle objects interactions w/ Workshop
//Return wether the object is taken from tavernkeeper
2020-12-04 21:49:58 +01:00
public bool use(GameObject object_used)
{
2020-12-05 13:38:13 +01:00
if(currentMug is null) //No mug in hand
{
2020-12-05 13:38:13 +01:00
if(object_used != null && object_used.tag=="Mug")
2020-12-04 21:49:58 +01:00
{
2020-12-05 13:38:13 +01:00
Mug mug = object_used.GetComponent<Mug>();
if (mug!= null && mug.content != null)
{
Debug.Log(gameObject.name+" take "+object_used.name+ " of "+mug.content.Type);
currentMug = object_used;
2020-12-07 15:40:34 +01:00
consumeTimer=consumeTime;
2020-12-05 13:38:13 +01:00
return true;
}
else
{
Debug.Log("Display order (or something else) of "+gameObject.name);
return false;
}
2020-12-04 21:49:58 +01:00
}
else
{
Debug.Log("Display order (or something else) of "+gameObject.name);
return false;
}
}
else
{
2020-12-05 13:38:13 +01:00
Debug.Log(gameObject.name+" already consumming "+currentMug.name);
return false;
}
}
// Start is called before the first frame update
void Start()
{
//Needs to be on Interactions layer and have the Client tag to work properly
gameObject.tag = "Client"; //Force gameobject tag
}
// Update is called once per frame
void Update()
{
2020-12-07 15:40:34 +01:00
//Timer
if (currentMug!= null) //Consuming mug if there's one
{
consumeTimer -= Time.deltaTime;
if (consumeTimer < 0) //Finished consuming mug ?
{
Mug obj = currentMug.GetComponent<Mug>();
if(obj !=null)
{
obj.consume();
//Drop mug
obj.drop(gameObject.transform.position+ (Vector3)Vector2.down * 0.2f);
currentMug=null;
}
}
}
}
}