Reputation: 23
i am trying to develop a melee combat game i am using edge collider and below code
i noticed that when i move or enable and disable the collider from the inspector everything goes but when i stand in my palace and use AttackCol.enabled = !AttackCol.enabled;
i cannot hit and the trigger function do not called
the only difference i see is the collider color when i add it from the inspector or while i am moving its color is normal but when i enable and disable it by code its color goes pale and do not do anything
public virtual void OnTriggerEnter2D(Collider2D collision)
{
if (DamageSources.Contains( collision.tag ))
{
StartCoroutine(TakeDamage());
}
}
Upvotes: 1
Views: 106
Reputation: 23
i added AttackCol.isTrigger = AttackCol.enabled; after AttackCol.enabled = !AttackCol.enabled; and everything geos ok right now but i think it is a work around but i need to know why the color goes pale ?
Upvotes: 0
Reputation: 1013
Stuff like AttackCol.enabled = !AttackCol.enabled;
is clever, but it can go wrong when that one is called (accidentally) more than once. I suggest trying it out in the simplest form AttackCol.enabled = true;
to make sure the error is not there. Later you can still make it more elegant again! :)
Upvotes: 1
Reputation: 343
virtual
from function definition.Upvotes: 2