- Home /
Question by
kyoto1601 · Nov 24, 2020 at 10:13 PM ·
randomrandom.range
how to make player randomly jump in some platform and not jump in some in doodle jump ?
i wrote a code for player to randomly jump in platform and dont jump .But when player jump more then 5 (i choice random no. (1,5)) in same platform it stop jumping ....i want it to keep jumping in some platform and never jump in some..plss help...
public class platform : MonoBehaviour { public float jumpForce = 10f;
void OnCollisionEnter2D(Collision2D collision)
{
Rigidbody2D rb = collision.collider.GetComponent<Rigidbody2D>();
if (UnityEngine.Random.Range(1, 5) > 1)
{
if (collision.relativeVelocity.y <= 0f)
{
if (rb != null)
{
Vector2 velocity = rb.velocity;
velocity.y = jumpForce;
rb.velocity = velocity;
}
}
}
else
{
if (collision.relativeVelocity.y <= 0f)
{
if(rb != null)
{
jumpForce = 0f;
Vector2 velocity = rb.velocity;
velocity.y = jumpForce;
rb.velocity = velocity;
Destroy(gameObject);
}
}
}
}
}
Comment