using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerControl : MonoBehaviour
{
// Start is called before the first frame update
moveForce = 20f;public float
jumpForce = 300f;public float
maxVelocity = 4f;public float
isGrounded;private bool
_score = 0;public int
Rigidbody2D myBody;private
Animator animator;private
Start()void
{
}
Awake()void
{
myBody = GetComponent<Rigidbody2D>();
animator = GetComponent<Animator>();
}
Update()void
{
// if (Static.s_score >= 10)
{
// Application.LoadLevel("Scene2");
}
}
// Update is called once per frame
FixedUpdate()void
{
PlayerWalk();
}
PlayerWalk()void
{
forceX = 0f;float
forceY = 0f;float
vel = Mathf.Abs(myBody.velocity.x);float
h = Input.GetAxisRaw(float "Horizontal");
(h > 0)if
{
(vel < maxVelocity)if
{
forceX = moveForce;
}
Vector3 scale = transform.localScale;
scale.x = 2f;
transform.localScale = scale;
animator.SetInteger( , 1);"state"
}
(h < 0)else if
{
(vel < maxVelocity)if
{
forceX = -moveForce;
}
Vector3 scale = transform.localScale;
scale.x = -2f;
transform.localScale = scale;
animator.SetInteger( , 1);"state"
}
(h == 0)else if
{
animator.SetInteger( , 0);"state"
}
(Input.GetKey(KeyCode.UpArrow))if
{
(isGrounded)if
{
isGrounded = ;false
forceY = jumpForce;
animator.SetInteger( , 2);"state"
}
}
(Input.GetKey(KeyCode.F))if
{
animator.SetInteger( , 4);"state"
}
(Input.GetKey(KeyCode.G))if
{
animator.SetInteger( , 3);"state"
}
(Input.GetKey(KeyCode.H))if
{
animator.SetInteger( , 5);"state"
}
myBody.AddForce( Vector2(forceX, forceY));new
}
OnCollisionEnter2D(Collision2D target)void
{
(target.gameObject.tag == )if "Ground"
{
isGrounded = ;true
}
}
}

Preview text:

using System.Collections;
using System.Collections.Generic; using UnityEngine;
public class PlayerControl : MonoBehaviour {
// Start is called before the first frame update public float moveForce = 20f;
public float jumpForce = 300f;
public float maxVelocity = 4f; private bool isGrounded; public int _score = 0; private Rigidbody2D myBody; private Animator animator; Start() void { } Awake() void { myBody = GetComponent(); animator = GetComponent(); } Update() void {
// if (Static.s_score >= 10) {
// Application.LoadLevel("Scene2"); } }
// Update is called once per frame FixedUpdate() void { PlayerWalk(); } PlayerWalk() void { float forceX = 0f; float forceY = 0f;
float vel = Mathf.Abs(myBody.velocity.x);
float h = Input.GetAxisRaw("Horizontal"); if (h > 0) { if (vel < maxVelocity) { forceX = moveForce; }
Vector3 scale = transform.localScale; scale.x = 2f; transform.localScale = scale;
animator.SetInteger("state", 1); } else if (h < 0) { if (vel < maxVelocity) { forceX = -moveForce; }
Vector3 scale = transform.localScale; scale.x = -2f; transform.localScale = scale;
animator.SetInteger("state", 1); } else if (h == 0) {
animator.SetInteger("state", 0); }
if (Input.GetKey(KeyCode.UpArrow)) { if (isGrounded) { isGrounded = false; forceY = jumpForce;
animator.SetInteger("state", 2); } } if (Input.GetKey(KeyCode.F)) {
animator.SetInteger("state", 4); } if (Input.GetKey(KeyCode.G)) {
animator.SetInteger("state", 3); } if (Input.GetKey(KeyCode.H)) {
animator.SetInteger("state", 5); }
myBody.AddForce(new Vector2(forceX, forceY)); } OnCollisionEnter2D(Collision2 void D target) { if (target.gameObject.tag == ) "Ground" { isGrounded = true; } } }