My code doesn´t work when i add _fall and _jump to a button script.
Code:
using UnityEngine;
using System.Collections;
public class PlayerController : PhysicsObject
{
public float upForce;
private bool isDead = false;
public float speed;
private Animator anim;
private Rigidbody2D rb2d;
void Start()
{
anim = GetComponent<Animator> ();
rb2d = GetComponent<Rigidbody2D>();
}
void Update(){
_jump();
_fall();
}
public void _jump(){
if (isDead == false && grounded)
{
anim.SetTrigger("Jump");
rb2d.velocity = Vector2.zero;
rb2d.AddForce(new Vector2(0, upForce));
}
}
public void _fall(){
if (isDead == false)
{
rb2d.velocity = Vector2.zero;
rb2d.AddForce(new Vector2(0,-speed));
}
}
void OnCollisionEnter2D(Collision2D other)
{
if (other.collider.tag == "Ground") {
rb2d.velocity = Vector2.zero;
isDead = true;
GameControl.instance.BirdDied ();
}
}
}