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);
}
}