Part of me doesn’t even know how to ask what I want to ask because I’ve been staring at this for so long trying to figure it out.
I’m making a little project, a metal detecting simulator of sorts, there are almost definitely better ways around it but I wanted to challenge myself and see what I could do, and I’ve managed to make it this far without asking for help.
HOWEVER. I have fallen flat on my face!.
Quick rundown, this script is responsible for the digging up of an item, It was all working perfectly not too long ago, but I wanted to try and add a Quality system (Junk, Common, so on), so I made an array (I’ve never used an array before believe it or not so that’s probably the issue!, I’ve read about them and seen them be used in videos, this is by far the most I’ve put into a project.
Anyway, the way it worked before was, the item to be dug up was tagged as “Ring”, if the collider from the detector collides with something tagged as “Ring” The detector would buzz, and you then knew where it was.
I wanted to have different items tagged as different qualities, and to be able to detect all of them, so I’ve tried nesting an If statement (Again not sure if this is the right way, just sort of made sense to me at the time).
So I’m asking for a fresh set of eyes, show me the way!
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class Trowel : MonoBehaviour
{
public float treasureCount;
public Text treasureText;
public bool treasureContact = false;
private bool keyDown;
private bool isDug;
public GameObject spawner;
string[] quality = new string[]{"Junk", "Common", "Rare", "Treasure", "Quest Item"};
public GameObject dirtPile;
void Update(){
treasureText.text = "Quest item found: " +treasureCount.ToString() ;
keyDown = Input.GetKey("e");
}
void OnTriggerStay(Collider col)
{
if(isDug == false && keyDown){
if(col.gameObject.tag == (quality[0]) || col.gameObject.tag == (quality[1]) || col.gameObject.tag == (quality[2]) || col.gameObject.tag == (quality[3]) || col.gameObject.tag == (quality[4]))
StartCoroutine(Dig());
isDug = true;
//print("Is this working?");
}
IEnumerator Dig(){
yield return new WaitForSeconds(0.1f);
treasureCount +=1;
Destroy(col.gameObject);
DirtPile();
yield return new WaitForSeconds(1.5f);
print("You found a " + col.tag +" Item");
}
}
void OnTriggerExit(Collider col){
isDug = false;
}
void DirtPile(){
Instantiate(dirtPile, spawner.transform.position, spawner.transform.rotation);
}
void itemPickUpNotification(){
}
}
Sorry for the wall of text, help is appreciated! ![]()
EDIT: I realise that col.tag should probably be, col.gameObject.tag Still doesn’t work, though.