mirror of
				https://github.com/nothke/quality-control.git
				synced 2025-10-31 16:35:57 +00:00 
			
		
		
		
	Right click hammer time!
This commit is contained in:
		| @@ -91,6 +91,7 @@ namespace Nothke.Interaction.Items | |||||||
|             if (itemInHands) return; |             if (itemInHands) return; | ||||||
|  |  | ||||||
|             item = _item as Interactable; |             item = _item as Interactable; | ||||||
|  |             item.manager = controller; | ||||||
|  |  | ||||||
|             if (_item.Rigidbody) |             if (_item.Rigidbody) | ||||||
|                 _item.Rigidbody.isKinematic = true; |                 _item.Rigidbody.isKinematic = true; | ||||||
| @@ -147,6 +148,8 @@ namespace Nothke.Interaction.Items | |||||||
|  |  | ||||||
|             Debug.Log($"Dropped {item.name}"); |             Debug.Log($"Dropped {item.name}"); | ||||||
|  |  | ||||||
|  |             item.manager = null; | ||||||
|  |  | ||||||
|             itemInHands = null; |             itemInHands = null; | ||||||
|             item = null; |             item = null; | ||||||
|         } |         } | ||||||
|   | |||||||
| @@ -10,7 +10,7 @@ GameObject: | |||||||
|   m_Component: |   m_Component: | ||||||
|   - component: {fileID: 2785315084969141824} |   - component: {fileID: 2785315084969141824} | ||||||
|   - component: {fileID: 5775974203735073309} |   - component: {fileID: 5775974203735073309} | ||||||
|   - component: {fileID: 586259664102464044} |   - component: {fileID: 6955740691028170723} | ||||||
|   - component: {fileID: 7152765985800576699} |   - component: {fileID: 7152765985800576699} | ||||||
|   m_Layer: 0 |   m_Layer: 0 | ||||||
|   m_Name: Hammer |   m_Name: Hammer | ||||||
| @@ -56,7 +56,7 @@ BoxCollider: | |||||||
|   serializedVersion: 3 |   serializedVersion: 3 | ||||||
|   m_Size: {x: 0.21280721, y: 0.83170784, z: 0.32937676} |   m_Size: {x: 0.21280721, y: 0.83170784, z: 0.32937676} | ||||||
|   m_Center: {x: 0, y: 0.08331621, z: 0} |   m_Center: {x: 0, y: 0.08331621, z: 0} | ||||||
| --- !u!114 &586259664102464044 | --- !u!114 &6955740691028170723 | ||||||
| MonoBehaviour: | MonoBehaviour: | ||||||
|   m_ObjectHideFlags: 0 |   m_ObjectHideFlags: 0 | ||||||
|   m_CorrespondingSourceObject: {fileID: 0} |   m_CorrespondingSourceObject: {fileID: 0} | ||||||
| @@ -65,7 +65,7 @@ MonoBehaviour: | |||||||
|   m_GameObject: {fileID: 4556969024762416753} |   m_GameObject: {fileID: 4556969024762416753} | ||||||
|   m_Enabled: 1 |   m_Enabled: 1 | ||||||
|   m_EditorHideFlags: 0 |   m_EditorHideFlags: 0 | ||||||
|   m_Script: {fileID: 11500000, guid: 84817382e549d8b4797caa3a4891df6b, type: 3} |   m_Script: {fileID: 11500000, guid: 05e9defb8535b9244b97ae031ed4d4ed, type: 3} | ||||||
|   m_Name:  |   m_Name:  | ||||||
|   m_EditorClassIdentifier:  |   m_EditorClassIdentifier:  | ||||||
|   manager: {fileID: 0} |   manager: {fileID: 0} | ||||||
|   | |||||||
							
								
								
									
										29
									
								
								Assets/Scripts/Interactable/Hammer.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										29
									
								
								Assets/Scripts/Interactable/Hammer.cs
									
									
									
									
									
										Normal file
									
								
							| @@ -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(); | ||||||
|  |                 } | ||||||
|  |             } | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  | } | ||||||
							
								
								
									
										11
									
								
								Assets/Scripts/Interactable/Hammer.cs.meta
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										11
									
								
								Assets/Scripts/Interactable/Hammer.cs.meta
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,11 @@ | |||||||
|  | fileFormatVersion: 2 | ||||||
|  | guid: 05e9defb8535b9244b97ae031ed4d4ed | ||||||
|  | MonoImporter: | ||||||
|  |   externalObjects: {} | ||||||
|  |   serializedVersion: 2 | ||||||
|  |   defaultReferences: [] | ||||||
|  |   executionOrder: 0 | ||||||
|  |   icon: {instanceID: 0} | ||||||
|  |   userData:  | ||||||
|  |   assetBundleName:  | ||||||
|  |   assetBundleVariant:  | ||||||
| @@ -2,26 +2,17 @@ | |||||||
| using Nothke.Interaction.Items; | using Nothke.Interaction.Items; | ||||||
| using UnityEngine; | 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<Product>(); |         var product = GetComponentInChildren<Product>(); | ||||||
|  |  | ||||||
|         if (!product) |         if (!product) | ||||||
|         { |  | ||||||
|             return; |             return; | ||||||
|         } |  | ||||||
|  |  | ||||||
|         var clip = product.Type.SelectClip(product.Defect != DefectType.None); |         var clip = product.Type.SelectClip(product.Defect != DefectType.None); | ||||||
|  |  | ||||||
|         clip.Play( |         clip.Play( | ||||||
|             transform.position, |             transform.position, | ||||||
|             Random.Range(0.8f, 1.2f)); |             Random.Range(0.8f, 1.2f)); | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user