diff --git a/Assets/Plugins/Interaction/Runtime/Items/Hands.cs b/Assets/Plugins/Interaction/Runtime/Items/Hands.cs index 2683a6b..7a6354a 100644 --- a/Assets/Plugins/Interaction/Runtime/Items/Hands.cs +++ b/Assets/Plugins/Interaction/Runtime/Items/Hands.cs @@ -91,6 +91,7 @@ namespace Nothke.Interaction.Items if (itemInHands) return; item = _item as Interactable; + item.manager = controller; if (_item.Rigidbody) _item.Rigidbody.isKinematic = true; @@ -147,6 +148,8 @@ namespace Nothke.Interaction.Items Debug.Log($"Dropped {item.name}"); + item.manager = null; + itemInHands = null; item = null; } diff --git a/Assets/Prefabs/Tools/Hammer.prefab b/Assets/Prefabs/Tools/Hammer.prefab index edba1aa..3c7e2d3 100644 --- a/Assets/Prefabs/Tools/Hammer.prefab +++ b/Assets/Prefabs/Tools/Hammer.prefab @@ -10,7 +10,7 @@ GameObject: m_Component: - component: {fileID: 2785315084969141824} - component: {fileID: 5775974203735073309} - - component: {fileID: 586259664102464044} + - component: {fileID: 6955740691028170723} - component: {fileID: 7152765985800576699} m_Layer: 0 m_Name: Hammer @@ -56,7 +56,7 @@ BoxCollider: serializedVersion: 3 m_Size: {x: 0.21280721, y: 0.83170784, z: 0.32937676} m_Center: {x: 0, y: 0.08331621, z: 0} ---- !u!114 &586259664102464044 +--- !u!114 &6955740691028170723 MonoBehaviour: m_ObjectHideFlags: 0 m_CorrespondingSourceObject: {fileID: 0} @@ -65,7 +65,7 @@ MonoBehaviour: m_GameObject: {fileID: 4556969024762416753} m_Enabled: 1 m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: 84817382e549d8b4797caa3a4891df6b, type: 3} + m_Script: {fileID: 11500000, guid: 05e9defb8535b9244b97ae031ed4d4ed, type: 3} m_Name: m_EditorClassIdentifier: manager: {fileID: 0} diff --git a/Assets/Scripts/Interactable/Hammer.cs b/Assets/Scripts/Interactable/Hammer.cs new file mode 100644 index 0000000..27de9a0 --- /dev/null +++ b/Assets/Scripts/Interactable/Hammer.cs @@ -0,0 +1,29 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; +using Nothke.Interaction; +using Nothke.Interaction.Items; + +public class Hammer : GenericItem +{ + private void Update() + { + if (manager && manager.hands.item == this) + { + if (Input.GetMouseButtonDown(1)) + { + if (manager.hovered is HammerableRigidbody hammerable) + { + hammerable.Hammer(); + + var hands = (manager.hands as Hands); + var hand = hands.hand; + + hand.transform.position = manager.hit.point; + hand.transform.localPosition += new Vector3(0f, -0.4f, 0f); // Offset to match the hammer head + hands.ResetOffset(); + } + } + } + } +} \ No newline at end of file diff --git a/Assets/Scripts/Interactable/Hammer.cs.meta b/Assets/Scripts/Interactable/Hammer.cs.meta new file mode 100644 index 0000000..3ad4c07 --- /dev/null +++ b/Assets/Scripts/Interactable/Hammer.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 05e9defb8535b9244b97ae031ed4d4ed +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Interactable/HammerableRigidbody.cs b/Assets/Scripts/Interactable/HammerableRigidbody.cs index 421c57a..a2e8a40 100644 --- a/Assets/Scripts/Interactable/HammerableRigidbody.cs +++ b/Assets/Scripts/Interactable/HammerableRigidbody.cs @@ -2,26 +2,17 @@ using Nothke.Interaction.Items; using UnityEngine; -public class HammerableRigidbody: RigidbodyInteractable +public class HammerableRigidbody : RigidbodyInteractable { - public override void Use(InteractionController im) + public void Hammer() { - manager = im; - - if (im.hands.item == null) - { - base.Use(im); - return; - } - var product = GetComponentInChildren(); if (!product) - { return; - } var clip = product.Type.SelectClip(product.Defect != DefectType.None); + clip.Play( transform.position, Random.Range(0.8f, 1.2f));