StellarXipher/Assets/Scripts/PipeTask/PipeFixZone.cs
nlevin6 0bec5d576c
All checks were successful
Build project / Build for (StandaloneLinux64, 6000.0.37f1) (push) Successful in 5m3s
Build project / Build for (StandaloneWindows64, 6000.0.37f1) (push) Successful in 19m21s
Build project / Publish to itch.io (StandaloneLinux64) (push) Successful in 11s
Build project / Publish to itch.io (StandaloneWindows64) (push) Successful in 11s
added pipe task
2025-04-14 21:07:16 -04:00

56 lines
1.5 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;
bool hasPipe = false;
for (int i = 0; i < inventory.slots.Length; i++)
{
var item = inventory.slots[i];
if (item != null && item.itemName == requiredItemName)
{
hasPipe = true;
break;
}
}
if (hasPipe && 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;
}
}
}
}
}