I’m making a game about building engines and surviving.
I have this Consumable
script but when i mean to consume one thing it consumes all of them and I don’t know how to fix this.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Consumable : MonoBehaviour
{
[SerializeField] private Camera cam;
[SerializeField] private float range;
[SerializeField] private GameObject Cursor;
[SerializeField] private GameObject Hand;
[SerializeField] private int RemoveThirst;
[SerializeField] private int RemoveHunger;
[SerializeField] private int AddThirst;
[SerializeField] private int AddHunger;
void Update()
{
RaycastHit hit;
if(Input.GetKeyDown(KeyCode.F) && Physics.Raycast(cam.transform.position, cam.transform.forward, out hit, range) && hit.transform.gameObject.tag == "ConsumableItem")
{
Hand.SetActive(false);
Cursor.SetActive(true);
ThirstCountScript1.thirst -= RemoveThirst;
ThirstCountScript1.hunger -= RemoveHunger;
ThirstCountScript1.thirst += AddThirst;
ThirstCountScript1.hunger += AddHunger;
Destroy(gameObject);
}
if(Physics.Raycast(cam.transform.position, cam.transform.forward, out hit, range ) && hit.transform.gameObject.tag == "ConsumableItem")
{
Hand.SetActive(true);
Cursor.SetActive(false);
}
else
{
Hand.SetActive(false);
Cursor.SetActive(true);
}
}
}