mirror of
https://github.com/nothke/quality-control.git
synced 2025-08-08 23:03:43 +00:00
Merge branch 'master' of https://github.com/nothke/quality-control
This commit is contained in:
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 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>();
|
||||
|
||||
if (!product)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var clip = product.Type.SelectClip(product.Defect != DefectType.None);
|
||||
|
||||
clip.Play(
|
||||
transform.position,
|
||||
Random.Range(0.8f, 1.2f));
|
||||
|
Reference in New Issue
Block a user