BoxCollider2D OnTriggerEnter2D
I'm going crazy with this, i have
Player gameObject(components: spriteRenderer, RigidBody2D, BoxCollider2D, BoxCollider2D, Animator, Script)
and
GroundCreator gameObject(components: none), it's position is 0,0,-10;
and i have next script
sing System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class BlockCreatorCheckCollision : MonoBehaviour {
public bool GroundDetected;
void OnTriggerEnter2D(Collider2D collider)
{
if (collider.gameObject.layer == LayerMask.NameToLayer("Block") && collider.CompareTag("Ground") || collider.gameObject.layer == LayerMask.NameToLayer("FallingTile") && collider.CompareTag("Ground"))
{
GroundDetected = true;
}
}
void OnTriggerStay2D(Collider2D collider)
{
if (collider.gameObject.layer == LayerMask.NameToLayer("Block") && collider.CompareTag("Ground") || collider.gameObject.layer == LayerMask.NameToLayer("FallingTile") && collider.CompareTag("Ground"))
{
GroundDetected = true;
}
}
void OnTriggerExit2D(Collider2D collider)
{
if (collider.gameObject.layer == LayerMask.NameToLayer("Block") && collider.CompareTag("Ground") || collider.gameObject.layer == LayerMask.NameToLayer("FallingTile") && collider.CompareTag("Ground"))
{
GroundDetected = false;
}
}
}
If i create
BlockCreatorCheck gameObject(components: Box Collider2D(is trigger set to true), script above)
and place it on my Player as child, my script detects Falling and Ground block when they enter the BoxCollider2D of BlockCreatorCheck,
but if i place that same BlockCreatorCheck on GroundCreator it only detects Falling blocks when they enter BoxCollider2D of BlockCreatorCheck and i checked a little bit, GroundBlocks don't even showup in OnTriggerEnter when my BlockCreatorCheck not on Player gameObject.
Where is the error???? I don't understand what's working wrong or not working at all...
Answer by Hadu · Apr 23, 2018 at 01:30 PM
I dont know what was that, but i've remade the prefab of my Ground block and now it can be detected....I suppose it was because type of rigidbody2d was static, but i'm not sure.
Your answer
Follow this Question
Related Questions
Collider2D OnTriggerEnter2D not working, IsTrigger=true and Collider2D IsTrigger=false 0 Answers
A box collider 2D (Is Trigger marked) stops my player from moving which has rigidbody 2D 1 Answer
All colliders not longer working 0 Answers
void OnTriggerEnter() not working properly? 0 Answers
Tilemap Collider not Colliding 0 Answers