Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class PlayerController : MonoBehaviour
- {
- Rigidbody2D rb;
- Animator anim;
- void Start()
- {
- rb = GetComponent<Rigidbody2D>();
- anim = GetComponent<Animator>();
- }
- void Update()
- {
- rb.velocity = new Vector2(Input.GetAxis("Horizontal") * 12f, rb.velocity.y);
- if (Input.GetKeyDown(KeyCode.Space))
- {
- PlayerJumping();
- anim.SetTrigger("IsJump");
- }
- if(Input.GetAxis("Horizontal") == 0)
- {
- anim.SetBool("IsRuning", true);
- }
- else
- {
- Flip();
- anim.SetBool("IsRuning", false);
- }
- }
- void PlayerJumping()
- {
- rb.AddForce(transform.up * 16f, ForceMode2D.Impulse);
- }
- void Flip()
- {
- if(Input.GetAxis("Horizontal") < 0)
- {
- transform.localRotation = Quaternion.Euler(0, 180, 0);
- }
- if (Input.GetAxis("Horizontal") > 0)
- {
- transform.localRotation = Quaternion.Euler(0, 0, 0);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement