Hi! Im a new to programing i have kind of big problem with my 2D Sphere Collider
.
I don’t know how to fix this issue. It might me more simple than i think.
Here’s the script:
void OnTriggerEnter2D (Collider2D collision)
{
bool colizjaCircle = GetComponent<CircleCollider2D>();
dotykaSciany = true;
Debug.Log("Touching a wall!");
slideParticle.Play();
if (colizjaCircle && dotykaSciany)
{
Debug.Log("Dotyka Sciany i podłogi!");
slideParticle.Stop();
}
}
thx if you will help me btw! ; )
Try this setup where you identify collider types by their tags
HashSet<Collider2D> DotykaneŚciany = new ();
HashSet<Collider2D> DotykanePodłogi = new ();
bool dotykaŚciany => DotykaneŚciany.Count!=0;
bool dotykaPodłogi => DotykanePodłogi.Count!=0;
void OnTriggerEnter2D ( Collider2D otherCollider )
{
if( otherCollider.CompareTag("Ściana") )
{
DotykaneŚciany.Add( otherCollider );
}
else if( otherCollider.CompareTag("Podłoga") )
{
DotykanePodłogi.Add( otherCollider );
}
if( dotykaŚciany && dotykaPodłogi )
{
Debug.Log( "Dotyka ściany i podłogi!" , otherCollider );
slideParticle.Stop();
}
if( dotykaŚciany && dotykaPodłogi==false )
{
Debug.Log( "Dotyka jedynie ściany!" , otherCollider );
slideParticle.Play();
}
}
void OnTriggerExit2D ( Collider2D otherCollider )
{
if( otherCollider.CompareTag("Ściana") )
{
DotykaneŚciany.Remove( otherCollider );
}
else if( otherCollider.CompareTag("Podłoga") )
{
DotykanePodłogi.Remove( otherCollider );
}
}