[CODING|2D] Walls that player is able to break through
I have been trying to create some code that when it detects a player in the trigger, it deactivates. I want to get to a point in which when you crash through the wall, it would slow the player down by at most 30%, but my problem right now is that when you enter the trigger, the wall the player is supposed to run into doesn't disappear. Here's my code so far:
public class wall : MonoBehaviour
{
void OnTriggerStay (Collider attachedRigidbody)
{
gameObject.SetActive (false);
}
// Use this for initialization
void Awake () {
}
}
The code is part of a sprite that does have Box Collider 2D enabled and has "Is Trigger" enabled. I am also using the player model/code included in the standard assets 2D pack. Please let me know if my wording was bad or you need more information.
Answer by hexagonius · Feb 16, 2017 at 08:16 PM
For 2D Physics to work you need to use 2D messages:
void OnTriggerStay2D (Collider2D attachedRigidbody)
while we're at it, this is better:void OnTriggerEnter2D (Collider2D attachedRigidbody)
Your answer
Follow this Question
Related Questions
Trigger Collider is Triggering? 0 Answers
AI and Enemy Detection 1 Answer
Change Scene with Physics Raycasting 1 Answer
How to Destroy A GameObject when it enters any Triggers 2 Answers
OnTriggerEnter2D Not Detecting BoxCollider2D - Childed Object 2 Answers