Okay, my other problem is solved, by myself, I might add. Yay! Now, I’ve been trying to make a fast-fall system, as is implemented in some fighter games (like Super Smash Bros). For some reason, I can crouch while in the air and do not fall faster. I know there’s a lot in this script but it’s the player-character script.
using UnityEngine;
using System.Collections;
public class PlayerController : MonoBehaviour
{
public float maxSpeed = 10f;
bool facingRight = true;
Animator anim;
public float jumpForce = 50f;
public float normalfall = 2f;
public float fastfall = 9f;
public bool grounded;
void Start ()
{
anim = GetComponent<Animator>();
this.rigidbody2D.gravityScale = normalfall;
}
void Update ()
{
}
void FixedUpdate ()
{
anim.SetFloat ("vSpeed", rigidbody2D.velocity.y);
if (grounded = true)
{
if (Input.GetButton ("Down"))
anim.SetBool ("Crouch", true);
if (Input.GetButtonUp ("Down"))
anim.SetBool ("Crouch", false);
}
else if (grounded = false) //This does not work
{
if (Input.GetButton ("Down"))
this.rigidbody2D.gravityScale = fastfall;
if (Input.GetButtonUp ("Down"))
this.rigidbody2D.gravityScale = normalfall;
}
float move = Input.GetAxis ("Horizontal");
anim.SetFloat ("Speed", Mathf.Abs (move));
if (move > 0 && !facingRight)
Flip ();
else if (move < 0 && facingRight)
Flip ();
rigidbody2D.velocity = new Vector2 (move * maxSpeed, rigidbody2D.velocity.y);
if (Input.GetButton ("Jump"))
{
grounded = false;
anim.SetBool ("grounded", false);
}
}
void OnCollisionStay2D ()
{
grounded = true;
anim.SetBool ("grounded", true);
if (grounded && Input.GetButtonDown ("Jump"))
{
rigidbody2D.AddForce(new Vector2(0, jumpForce));
}
}
void Flip()
{
facingRight = !facingRight;
Vector3 theScale = transform.localScale;
theScale.x *= -1;
transform.localScale = theScale;
}
}