I found tutorials for jumping on it but not over it. How do I do it so not only you need to jump over it but need to jump over it twice to destroy it? I am using Unity 2d 8.1
It’s a third person view.
I found tutorials for jumping on it but not over it. How do I do it so not only you need to jump over it but need to jump over it twice to destroy it? I am using Unity 2d 8.1
It’s a third person view.
Make a script that you will put on your object that shoots a ray upwards. Make a private field called timesJumped (or something). in your update you will check if the ray has hit your player If true, increment timesJumped += 1. and in update check if timesJumped has hit your desiredAmount then call an event to destroy it.
private timesJumped = 0;
private void Update()
{
RaycastHit hit;
if(Physics.Raycast(new Ray(gameObject.transform.position, Vector3.up), out hit, 10f))
{
if(hit.collider.tag == "Player" && timesJumped <= 2)
{
timesJumped += 1;
}
else if(hit.collider.tag == "Player" && timesJumped >= 2)
{
Destroy(gameObject);
}
}
Haven’t tested but should work.