ProjetPatate/Assets/Scripts/Cleaning_workshop.cs

55 lines
1.7 KiB
C#
Raw Normal View History

2020-12-07 17:23:47 +01:00
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
//Define the behavior of a cleaning workshop
2020-12-10 13:51:16 +01:00
public class Cleaning_workshop : Workshop
2020-12-07 17:23:47 +01:00
{
2020-12-10 14:38:20 +01:00
List<GameObject> stock = new List<GameObject>(); //List of mug in workshop
2020-12-07 17:23:47 +01:00
//Handle objects interactions w/ Workshop
//Return wether the object is taken from tavernkeeper
2020-12-10 13:51:16 +01:00
public override bool use(GameObject object_used)
2020-12-07 17:23:47 +01:00
{
2020-12-10 14:38:20 +01:00
if(object_used != null)
2020-12-07 17:23:47 +01:00
{
2020-12-10 14:38:20 +01:00
//TODO : Gérer grabable autre que Mug
if(object_used.tag=="Grabable")
2020-12-07 17:23:47 +01:00
{
2020-12-10 14:38:20 +01:00
//Stock and empty mug
Mug mug = object_used.GetComponent<Mug>();
if (mug!= null)
{
Debug.Log(object_used.name+ " stocked in "+gameObject.name);
if (mug.content != null)//Empty mug
mug.consume();
stock.Add(object_used);
return true; //Object taken
}
}
else if(object_used.tag=="Player")
{
Tavernkeeper_controller player = object_used.GetComponent<Tavernkeeper_controller>();
if(player!=null && currentMug!=null)
{
Mug mug = currentMug.GetComponent<Mug>();
mug.dirty=false;
player.grab(currentMug);
}
2020-12-07 17:23:47 +01:00
}
}
return false;
}
2020-12-10 14:38:20 +01:00
// Update is called once per frame
void Update()
{
//Set current mug if there's stock
if(currentMug is null && stock.Count>0)
{
currentMug=stock[0];
stock.RemoveAt(0);
}
}
2020-12-07 17:23:47 +01:00
}