Question by
perendl · Mar 20, 2016 at 02:15 AM ·
c#ontriggerentertagdictionaryother-object
Check if other.object changes his tag (OnTriggerStay2D)
Hey there! I want to check if an Object with a Tag in my 2DCollider(Trigger) change his Tag to another Tag, how could i do that?
Thats my code for now:
public Dictionary<GameObject, float> Dic_objects = new Dictionary<GameObject, float>();
...
void OnTriggerStay2D(Collider2D other)
{
if (other.gameObject.CompareTag("object_1") &&!Dic_objects.ContainsKey(other.gameObject))
{
Dic_objects.Add(other.gameObject, 1);
}
if (other.gameObject.transform.tag == "object_2" && !Dic_objects.ContainsKey(other.gameObject))
{
Debug.Log("Test");
}**
if (other.gameObject.CompareTag("object_2") && !Dic_objects.ContainsKey(other.gameObject))
{
Dic_objects.Add(other.gameObject, 2);
}
}
void OnTriggerExit2D(Collider2D other)
{
if (other.gameObject.CompareTag("object_1") && Dic_objects.ContainsKey(other.gameObject))
{
Dic_objects.Remove(other.gameObject);
}
if (other.gameObject.CompareTag("object_2") && Dic_objects.ContainsKey(other.gameObject))
{
Dic_objects.Remove(other.gameObject);
}
}
My problem is that if the Tag changes while the object with the tag is in the collider it wont change in the dictionairy.
Ty for reading and coming answers, excuse my bad english.
Comment