Working Cleaning_workshop
This commit is contained in:
parent
f71d1e8b62
commit
c8682b208a
2 changed files with 44 additions and 17 deletions
|
@ -5,22 +5,50 @@ using UnityEngine;
|
|||
//Define the behavior of a cleaning workshop
|
||||
public class Cleaning_workshop : Workshop
|
||||
{
|
||||
// List<GameObject> stock = new List<GameObject>(); //List of mug in workshop
|
||||
List<GameObject> stock = new List<GameObject>(); //List of mug in workshop
|
||||
|
||||
//Handle objects interactions w/ Workshop
|
||||
//Return wether the object is taken from tavernkeeper
|
||||
public override bool use(GameObject object_used)
|
||||
{
|
||||
if(object_used != null && object_used.tag=="Grabable")
|
||||
if(object_used != null)
|
||||
{
|
||||
Mug mug = object_used.GetComponent<Mug>();
|
||||
if (mug!= null && mug.content is null && mug.dirty) //Mug dirty & empty
|
||||
//TODO : Gérer grabable autre que Mug
|
||||
if(object_used.tag=="Grabable")
|
||||
{
|
||||
Debug.Log(object_used.name+ "cleaned by"+gameObject.name);
|
||||
mug.dirty=false;
|
||||
return false;
|
||||
//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);
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,14 +20,18 @@ public class Tavernkeeper_controller : MonoBehaviour
|
|||
float horizontal;
|
||||
float vertical;
|
||||
float hands;
|
||||
string currentHand;
|
||||
|
||||
Vector2 lookDirection = new Vector2(1,0);
|
||||
Rigidbody2D rigidbody2d;
|
||||
Animator animator;
|
||||
|
||||
//TODO: assigner automatiquement à une autre mains si pleine
|
||||
public void grab(GameObject obj, string hand)
|
||||
public void grab(GameObject obj, string hand=null)
|
||||
{
|
||||
//Default hand
|
||||
if(hand is null)
|
||||
hand = currentHand;
|
||||
|
||||
//Test
|
||||
if(!hand_container.ContainsKey(hand))
|
||||
{
|
||||
|
@ -98,15 +102,10 @@ public class Tavernkeeper_controller : MonoBehaviour
|
|||
actionTimer= action_cd;
|
||||
isInteracting=true;
|
||||
if(hands>0)
|
||||
{
|
||||
// Debug.Log("Left hand");
|
||||
handAction("left");
|
||||
}
|
||||
currentHand="left";
|
||||
else
|
||||
{
|
||||
// Debug.Log("Right hand");
|
||||
handAction("right");
|
||||
}
|
||||
currentHand="right";
|
||||
handAction(currentHand);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue