My character is a square which can spin in any angle but it can not jump in certain angle.
Can anyone help?
public class Player: MonoBehaviour {
public float maxspeed = 10f;
bool facingRight = true;
Animator anim;
bool grounded = false;
public Transform groundCheck;
float groundRadius = 0.2f;
public LayerMask whatIsGround;
public float jumpFocre = 500f;
bool doubleJump = false;
void Start ()
{
anim = GetComponent ();
}
void FixedUpdate () {
grounded = Physics2D.OverlapCircle(groundCheck.position, groundRadius, whatIsGround);
anim.SetBool ("Ground", grounded);
if (grounded)
doubleJump = false;
float move = Input.GetAxis ("Horizontal");
anim.SetFloat ("Speed", Mathf.Abs (move));
GetComponent().velocity = new Vector2(move * maxspeed, GetComponent().velocity.y);
}
void Update()
{
if((grounded || !doubleJump) && Input.GetKeyDown ("up"))
{
anim.SetBool("Ground", false);
GetComponent().AddForce(new Vector2(0, jumpFocre));
if(!doubleJump && !grounded)
doubleJump = true;
}
}
void Flip()
{
facingRight = !facingRight;
Vector3 theScale = transform.localScale;
theScale.x *= -1;
transform.localScale = theScale;
}
}
No comments:
Post a Comment