Hi everyone.
I’m new programing Games.
I’m making a simple 2D platform… i have an unstable platform wich should disable its 2D collider after one second the player steps in.
The video shows the example to what i’ve achieved so far.
public class BaseUnstable : MonoBehaviour
{
public Animator animator;
void Start()
{
animator = GetComponent<Animator> ();
}
void OnCollisionEnter2D (Collision2D collision)
{
if (collision.gameObject.tag == "Player")
{
animator.SetTrigger ("Boost");
GetComponent<AudioSource>().Play ();
}
}
}
There are quite a few way to do it. You can just put the collider on that part of the bridge and then when the timer is up… or the animation (you can use an animation event at the end of the animation if it is an animation) and just put Destroy(bridge_gameObject);
You can also, make the bridge a prefab, then instantiate it and destroy the instantiated one. Which is what I would personally do. Or, you can Keep the bridge there, add a child object to the bridge that has the collider and destroy the child object.
That’s just thinking off the top of my head. You can also just make the collider a trigger when the bridge falls. Triggers don’t cause collisions.
I agree with Vakabaka, however, I would make a void and make the collider do whatever you want in an animation event. That way it is timed perfectly with the animation. But that’s just nitpicking