Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class PlayerControl : MonoBehaviour {
- Animator animator;
- float directionX = 0;
- float directionY = 0;
- bool walking = false;
- float h;
- float v;
- /* Use this for initialization */
- void Start () {
- animator = GetComponent<Animator>();
- }
- /* Update is called once per frame */
- void Update () {
- if (animator)
- {
- h = Input.GetAxisRaw("Horizontal");
- v = Input.GetAxisRaw("Vertical");
- walking = true;
- if (h > 0) //「→」↘
- {
- directionX = 1;
- directionY = -0.5F;
- }
- else if (h < 0) //「←」↖
- {
- directionX = -1;
- directionY = 0.5F;
- }
- else if (v > 0) //「↑」↗
- {
- directionX = 1;
- directionY = 0.5F;
- }
- else if (v < 0) //「↓」↙
- {
- directionX = -1;
- directionY = -0.5F;
- }
- else
- {
- walking = false;
- }
- }
- else
- {
- walking = false;
- }
- if (walking == true)
- {
- transform.Translate(new Vector3(directionX, directionY, 0));
- }
- animator.SetFloat("Direction_X", directionX);
- animator.SetFloat("Direction_Y", directionY);
- animator.SetBool("isWalk", walking);
- walking = false;
- }
- }
Add Comment
Please, Sign In to add comment