I’m trying to code a mechanic where the player can jump on enemies’ heads and get an extra ‘double jump’ when successfully sticking a jump. I’m a pretty big unity noob, so I’m having some problems. Any ideas on how I can actually make the character get a force applied after successful collision?
// Use this for initialization
void Start () {
}
// Update is called once per frame
void FixedUpdate () {
}
void OnCollisionEnter(Collision collision)
{
if (collision.collider.gameObject.tag == "EnemyHead")
{
if (transform.position.y >= collision.collider.transform.position.y)
{
collision.gameObject.GetComponent<Rigidbody>().AddForce (0, forceApplied, 0);
Destroy(collision.collider.transform.parent.gameObject);
Destroy(collision.collider.gameObject);
GameManager.score += 100;
}
}
else if (collision.collider.gameObject.tag == "EnemyBody")
//gamescore/death
{
GameManager.lives -= 1;
Debug.Log(GameManager.lives);
if (GameManager.lives == 0)
{
GameManager.over = true;
Time.timeScale = 0;
}
else
{
SceneManager.LoadScene("game on level1");
}
}
}
}