From ed07f1332e757457f88fd5ce20a13d8a11933d41 Mon Sep 17 00:00:00 2001 From: Antoine H Date: Thu, 10 Dec 2020 15:38:47 +0100 Subject: [PATCH] =?UTF-8?q?Modif=20utilisation=20g=C3=A9n=C3=A9rique=20des?= =?UTF-8?q?=20IGrabable=20quand=20action=20sans=20hit?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Assets/Scripts/Mug.cs | 7 ++++++- Assets/Scripts/Tavernkeeper_controller.cs | 17 +++++------------ 2 files changed, 11 insertions(+), 13 deletions(-) diff --git a/Assets/Scripts/Mug.cs b/Assets/Scripts/Mug.cs index 7212fa8..b989baf 100644 --- a/Assets/Scripts/Mug.cs +++ b/Assets/Scripts/Mug.cs @@ -14,7 +14,12 @@ public class Mug : MonoBehaviour, IGrabable //TODO: Gérer objets tavernier (drop) et autres public bool use(GameObject userObject) { - //Do nothing + if(userObject.tag=="Player") + { + // Debug.Log(gameObject.name+" dropped by "+userObject.name); + drop(userObject.transform.position); + return true; //Object taken (on the floor) + } return false; //Return wether the object is taken from tavernkeeper } public void take() //Object taken diff --git a/Assets/Scripts/Tavernkeeper_controller.cs b/Assets/Scripts/Tavernkeeper_controller.cs index 53f1042..d0f9f22 100644 --- a/Assets/Scripts/Tavernkeeper_controller.cs +++ b/Assets/Scripts/Tavernkeeper_controller.cs @@ -168,20 +168,13 @@ public class Tavernkeeper_controller : MonoBehaviour } } } - else if (hand_container[hand] != null) //Hand full and no hits + else if (hand_container[hand] != null) //Hand full and no hits : use object { - if (hand_container[hand].tag == "Grabable") //Drop obj carried on player position + IGrabable obj = hand_container[hand].GetComponent(); + if(obj !=null) { - IGrabable obj = hand_container[hand].GetComponent(); - if(obj !=null) - { - obj.drop(rigidbody2d.position); - hand_container[hand]=null; - } - } - else - { - Debug.Log(gameObject+" doesn't handle Hand full with "+ hand_container[hand]); + if(obj.use(gameObject)) //Use object in hand + hand_container[hand]=null; //True = object dropped } } }