Oops false script sry, Here is the right:
using UnityEngine;
using System.Collections;
public class Player : MonoBehaviour {
//Floats
public float maxSpeed = 3;
public float speed = 50f;
public float jumpPower = 150f;
//Booleans
public bool grounded;
public bool canDoubleJump;
//Stats
public int curHealth;
public int maxHealth = 3;
//References
private Rigidbody2D rb2d;
private Animator anim;
void Start ()
{
rb2d = gameObject.GetComponent();
anim = gameObject.GetComponent();
curHealth = maxHealth;
}
void Update ()
{
anim.SetBool(“Grounded”,grounded);
anim.SetFloat(“Speed”, Mathf.Abs(rb2d.velocity.x));
if (Input.GetAxis(“Horizontal”) < -0.1f)
{
transform.localScale = new Vector3(-1, 1, 1);
}
if (Input.GetAxis(“Horizontal”) > 0.1f)
{
transform.localScale = new Vector3(1, 1, 1);
}
if (Input.GetButtonDown(“Jump”))
{
if (grounded && Input.GetButtonDown(“Jump”))
{
rb2d.AddForce(Vector2.up * jumpPower);
grounded = false;
}
else
{
if (canDoubleJump)
{
canDoubleJump = false;
rb2d.velocity = new Vector2(rb2d.velocity.x, 0);
rb2d.AddForce(Vector2.up * jumpPower / 1.75f);
}
}
}
if(curHealth > maxHealth){
curHealth = maxHealth;
}
if(curHealth <= 0){
curHealth = 0;
Die ();
}
}
void FixedUpdate()
{
{
}
Vector3 easeVelocity = rb2d.velocity;
easeVelocity.y = rb2d.velocity.y;
easeVelocity.z = 0.0f;
easeVelocity.x *= 0.75f;
float h = Input.GetAxis(“Horizontal”);
//Fake friction / Easing the x speed of our player
if (grounded)
{
rb2d.velocity = easeVelocity;
}
//Moving the player
rb2d.AddForce((Vector2.right * speed) * h);
//Limiting the speed of the player
if (rb2d.velocity.x > maxSpeed)
{
rb2d.velocity = new Vector2(maxSpeed, rb2d.velocity.y);
}
if (rb2d.velocity.x < -maxSpeed)
{
rb2d.velocity = new Vector2(-maxSpeed, rb2d.velocity.y);
}
}
void Die(){
Application.LoadLevel(Application.loadedLevel);
}
public void Damage(int dmg){
curHealth -= dmg;
gameObject.GetComponent().Play(“RedFlash1”);
}
public IEnumerator KnockBack (float knockDur, float knockBackPwr, Vector3 knockBackDir)
{
float timer = 0;
while (knockDur>timer) {
timer += Time.deltaTime;
rb2d.velocity = new Vector2 (0, 0);
rb2d.AddForce (new Vector3 (knockBackDir.x * -10, knockBackDir.y * knockBackPwr, transform.position.z));
}
yield return 0;
}
}