0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

プレイヤーの上下左右の移動と攻撃※編集中

Posted at
Player.cs
using UnityEngine;
using System.Collections;

public class Player : MonoBehaviour
{

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

    void Start()
    {
        characterController = GetComponent<CharacterController>();
        animator = GetComponent<Animator>();
    }

     void Update()
    {
        if (Input.GetButtonDown("Fire1"))

        {
            animator.SetBool("Attack", true);
        }
        if (characterController.isGrounded)
        {
            velocity = new Vector3(Input.GetAxis("Horizontal"), 0f, Input.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);
    }
}
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?