Question by
pavlicsek4 · Jan 09, 2018 at 07:37 PM ·
triggertextontriggerenter
Hey there it may be stupid but can someone help me, why is my counter not working ?,Hello there, sorry it may be a bit stupid but i cannot figure it out why it does not count the collected items.
using System.Collections; using System.Collections.Generic; using UnityEngine.UI; using UnityEngine;
public class Felvesz : MonoBehaviour {
public GameObject Panel;
public GameObject[] Ikonok;
void OnTriggerEnter(Collider collision)
{
foreach(Transform child in Panel.transform)
{
if(child.gameObject.tag == collision.gameObject.tag)
{
string gyerek = child.Find("Text").GetComponent<Text>().text;
int szamol = System.Int32.Parse(gyerek) + 1;
child.Find("Text").GetComponent<Text>().text = "" + szamol;
return;
}
}
GameObject x;
if (collision.gameObject.tag == "Kaja")
{
x = Instantiate(Ikonok[0]);
x.transform.SetParent(Panel.transform);
}
if (collision.gameObject.tag == "Kaja2")
{
x = Instantiate(Ikonok[1]);
x.transform.SetParent(Panel.transform);
}
if (collision.gameObject.tag == "Pancel")
{
x = Instantiate(Ikonok[2]);
x.transform.SetParent(Panel.transform);
}
if (collision.gameObject.tag == "Sisak")
{
x = Instantiate(Ikonok[3]);
x.transform.SetParent(Panel.transform);
}
if (collision.gameObject.tag == "Pajzs")
{
x = Instantiate(Ikonok[4]);
x.transform.SetParent(Panel.transform);
}
}
} ,using System.Collections; using System.Collections.Generic; using UnityEngine.UI; using UnityEngine;
public class Felvesz : MonoBehaviour {
public GameObject Panel;
public GameObject[] Ikonok;
void OnTriggerEnter(Collider collision)
{
foreach(Transform child in Panel.transform)
{
if(child.gameObject.tag == collision.gameObject.tag)
{
string gyerek = child.Find("Text").GetComponent<Text>().text;
int szamol = System.Int32.Parse(gyerek) + 1;
child.Find("Text").GetComponent<Text>().text = "" + szamol;
return;
}
}
GameObject x;
if (collision.gameObject.tag == "Kaja")
{
x = Instantiate(Ikonok[0]);
x.transform.SetParent(Panel.transform);
}
if (collision.gameObject.tag == "Kaja2")
{
x = Instantiate(Ikonok[1]);
x.transform.SetParent(Panel.transform);
}
if (collision.gameObject.tag == "Pancel")
{
x = Instantiate(Ikonok[2]);
x.transform.SetParent(Panel.transform);
}
if (collision.gameObject.tag == "Sisak")
{
x = Instantiate(Ikonok[3]);
x.transform.SetParent(Panel.transform);
}
if (collision.gameObject.tag == "Pajzs")
{
x = Instantiate(Ikonok[4]);
x.transform.SetParent(Panel.transform);
}
}
}
Comment