Playerを歩かせる

歩く機能の実装
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerController : MonoBehaviour
{
public float walkSpeed;
private float speed;
private Vector3 movement;
private CharacterController controller;
void Start()
{
controller = GetComponent<CharacterController>();
speed = walkSpeed;
}
void Update()
{
PlayerMove();
}
void PlayerMove()
{
float moveH = Input.GetAxis("Horizontal");
float moveV = Input.GetAxis("Vertical");
movement = new Vector3(moveH, 0, moveV);
controller.Move(movement * Time.deltaTime * speed);
}
}





【2021版】X_Mission(全34回)
他のコースを見る
歩く機能の実装
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerController : MonoBehaviour
{
public float walkSpeed;
private float speed;
private Vector3 movement;
private CharacterController controller;
void Start()
{
controller = GetComponent<CharacterController>();
speed = walkSpeed;
}
void Update()
{
PlayerMove();
}
void PlayerMove()
{
float moveH = Input.GetAxis("Horizontal");
float moveV = Input.GetAxis("Vertical");
movement = new Vector3(moveH, 0, moveV);
controller.Move(movement * Time.deltaTime * speed);
}
}





Playerを歩かせる