プレーヤーを作成して動かす










前進後退と旋回
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerController : MonoBehaviour {
private CharacterController controller;
private Vector3 moveDirection = Vector3.zero;
public float gravity = 9.8f;
public float speedZ;
void Start(){
controller = GetComponent<CharacterController> ();
}
void Update(){
if (controller.isGrounded) {
moveDirection.z = Input.GetAxis ("Vertical") * Time.deltaTime * speedZ;
transform.Rotate (0, Input.GetAxis ("Horizontal") * 2, 0);
}
moveDirection.y -= gravity * Time.deltaTime;
Vector3 globalDirection = transform.TransformDirection (moveDirection);
controller.Move (globalDirection);
}
}





EscapeCombat(メモ)
他のコースを見る









前進後退と旋回
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerController : MonoBehaviour {
private CharacterController controller;
private Vector3 moveDirection = Vector3.zero;
public float gravity = 9.8f;
public float speedZ;
void Start(){
controller = GetComponent<CharacterController> ();
}
void Update(){
if (controller.isGrounded) {
moveDirection.z = Input.GetAxis ("Vertical") * Time.deltaTime * speedZ;
transform.Rotate (0, Input.GetAxis ("Horizontal") * 2, 0);
}
moveDirection.y -= gravity * Time.deltaTime;
Vector3 globalDirection = transform.TransformDirection (moveDirection);
controller.Move (globalDirection);
}
}





プレーヤーを作成して動かす