プレイヤーの移動と攻撃 Verバーチャルパッド対応版

PlayerJoystickVer.cs
using UnityEngine;
using System.Collections;
using UnityStandardAssets.CrossPlatformInput;

public class PlayerJoystickVer : MonoBehaviour
{

    private CharacterController characterController;
    private Vector3 velocity;
    [SerializeField]
    private float walkSpeed;
    private Animator animator;

    // Use this for initialization
    void Start()
    {
        characterController = GetComponent<CharacterController>();
        animator = GetComponent<Animator>();
    }

    // Update is called once per frame
    void Update()
    {
        if (Input.GetButtonDown("Fire1"))

        {
            animator.SetBool("Attack", true);
        }

        if (characterController.isGrounded)
        {

            velocity = new Vector3(CrossPlatformInputManager.GetAxis("Horizontal"), 0f, CrossPlatformInputManager.GetAxis("Vertical"));

            if (velocity.magnitude > 0.1f)
            {
                animator.SetBool("isRunning", true);
                transform.LookAt(transform.position + velocity);
            }
            else
            {
                animator.SetBool("isRunning", false);
            }
        }
        velocity.y += Physics.gravity.y * Time.deltaTime;
        characterController.Move(velocity * walkSpeed * Time.deltaTime);
    }
}
Sign up for free and join this conversation.
Sign Up
If you already have a Qiita account log in.