Question by
Nixron · Aug 31, 2016 at 05:07 PM ·
variablepublic variablepublic strings
Search for a tag using an Enum
Hey, I'm trying to search for a tag using an Enum as the text, so that i can change the searched tag on different game objects. I have the basic Enum That I need, but I don't know exactly how to implement it into a tag search. Here is the code that I have so far. Thanks for any help in advance!
[SerializeField]
public enum CraftingItem
{
Stick,
Rock,
Cloth
}
public CraftingItem crfOneEnum;
public CraftingItem crfTwoEnum;
public bool isRecoverable = false;
public int objOneCounter = 0;
public int objTwoCounter = 0;
public int objOneMax = 0;
public int objTwoMax = 0;
public Transform crfClone;
public Transform crfMain;
public Text crfOne;
public Text crfTwo;
void Start() {
}
void Update() {
crfOne.text = crfOneEnum + ":" + objOneCounter + "/" + objOneMax;
crfTwo.text = crfTwoEnum + ":" + objTwoCounter + "/" + objTwoMax;
}
void OnTriggerEnter(Collider col)
{
if (col.gameObject.tag == ("Stick") && objOneCounter < objOneMax)
{
objOneCounter = objOneCounter + 1;
Destroy(col.gameObject);
}
else if (col.gameObject.tag == ("Rock") && objTwoCounter < objTwoMax)
{
objTwoCounter = objTwoCounter + 1;
Destroy(col.gameObject);
}
if (objOneCounter == objOneMax && objTwoCounter == objTwoMax)
{
SpawnObj();
}
}
void SpawnObj() {
crfMain = (Transform)Instantiate(crfClone, new Vector3( transform.position.x, transform.position.y, transform.position.z), Quaternion.identity);
Destroy(this.gameObject);
}
}
Comment
Best Answer
Answer by Nixron · Aug 31, 2016 at 07:26 PM
Nevermind. I used a string array instead and it worked great.
Your answer
Follow this Question
Related Questions
Can't change value of my variable from another script. 0 Answers
Animator does not show up 0 Answers
Use enum hidden value as something other than int? (C#) 2 Answers
Adding to variable only once? 0 Answers
Logical explaination of this code 1 Answer