All checks were successful
Build project / Build for (StandaloneLinux64, 6000.0.37f1) (push) Successful in 5m7s
Build project / Build for (StandaloneWindows64, 6000.0.37f1) (push) Successful in 5m15s
Build project / Publish to itch.io (StandaloneLinux64) (push) Successful in 10s
Build project / Publish to itch.io (StandaloneWindows64) (push) Successful in 10s
47 lines
1.3 KiB
C#
47 lines
1.3 KiB
C#
using UnityEngine;
|
|
|
|
public class PipeFixZone : MonoBehaviour
|
|
{
|
|
public string requiredItemName = "Pipe";
|
|
public GameObject fixedPipeVisual;
|
|
|
|
private bool isFixed = false;
|
|
|
|
void Start()
|
|
{
|
|
if (fixedPipeVisual != null)
|
|
fixedPipeVisual.SetActive(false);
|
|
}
|
|
|
|
void Update()
|
|
{
|
|
if (isFixed) return;
|
|
|
|
Inventory inventory = FindObjectOfType<Inventory>();
|
|
if (inventory == null) return;
|
|
|
|
var heldItem = inventory.slots[inventory.currentSlot];
|
|
|
|
if (heldItem != null && heldItem.itemName == requiredItemName && Input.GetMouseButtonDown(0))
|
|
{
|
|
Ray ray = new Ray(Camera.main.transform.position, Camera.main.transform.forward);
|
|
int layerMask = ~LayerMask.GetMask("Player");
|
|
|
|
if (Physics.Raycast(ray, out RaycastHit hit, 3f, layerMask))
|
|
{
|
|
if (hit.transform == transform)
|
|
{
|
|
inventory.slots[inventory.currentSlot] = null;
|
|
inventory.EquipSlot(inventory.currentSlot);
|
|
|
|
if (fixedPipeVisual != null)
|
|
fixedPipeVisual.SetActive(true);
|
|
|
|
isFixed = true;
|
|
GetComponent<Collider>().enabled = false;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|