Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using Assets.HeroEditor.Common.CharacterScripts;
- using UnityEngine;
- public class PlayerMovement : MonoBehaviour {
- public float XAxis;
- public float YAxis;
- public CharacterController2D controller;
- public Animator anim;
- public float runSpeed = 40f;
- public Joystick joystick;
- float horizontalMove = 0f;
- bool Jump = false;
- bool Crouch = false;
- public Character Character;
- private void OnTriggerEnter2D(Collider2D other){
- if(other.gameObject.CompareTag("Coins"))
- {
- Destroy(other.gameObject);
- }
- if (other.tag == "Fall")
- {
- Vector2 newPosition = new Vector2(XAxis,YAxis);
- transform.position = newPosition;
- }
- }
- // Update is called once per frame
- void Update () {
- //horizontalMove = Input.GetAxisRaw("Horizontal") * runSpeed;
- horizontalMove = joystick.Horizontal * runSpeed;
- controller.Move(horizontalMove * Time.fixedDeltaTime, Crouch, Jump);
- Jump = false;
- //This Is for Idle Animation
- if (Input.GetAxisRaw("Horizontal") == 1)
- {
- Character.Animator.SetBool("Idle", true);
- }
- else if (Input.GetAxisRaw("Horizontal") == -1)
- {
- Character.Animator.SetBool("Idle", true);
- }
- else
- {
- Character.Animator.SetBool("Idle", false);
- }
- //This Is for jumping Animation
- if (Input.GetButtonDown("Jump"))
- {
- Jump = true;
- Character.Animator.SetBool("Jump", true);
- }else
- {
- Jump = false;
- Character.Animator.SetBool("Jump", false);
- }
- //This Is for Crouching Animation
- if (Input.GetButtonDown("Crouch"))
- {
- Crouch = true;
- Character.Animator.SetBool("Crouch", true);
- } else if (Input.GetButtonUp("Crouch"))
- {
- Crouch = false;
- Character.Animator.SetBool("Crouch", false);
- }
- //This Is for Walking Animation
- if (joystick.Horizontal >= 0.4)
- {
- Character.Animator.SetBool("Walk", true);
- }else if (joystick.Horizontal <= -0.4)
- {
- Character.Animator.SetBool("Walk", true);
- }else
- {
- Character.Animator.SetBool("Walk", false);
- }
- //This Is for Running Animation
- if (joystick.Horizontal >= 0.5)
- {
- Character.Animator.SetBool("Run", true);
- }else if (joystick.Horizontal <= -0.5)
- {
- Character.Animator.SetBool("Run", true);
- }else
- {
- Character.Animator.SetBool("Run", false);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement