テストキャラを作成して動かす
テストキャラを動かす
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class TestMove : MonoBehaviour
{
private CharacterController controller;
private Vector3 moveDirection = Vector3.zero;
void Start()
{
controller = GetComponent<CharacterController>();
}
void Update()
{
moveDirection.z = Input.GetAxis("Vertical");
transform.Rotate(0, Input.GetAxis("Horizontal") * 6f, 0);
if(moveDirection.magnitude > 0.1f)
{
Vector3 globalDirection = transform.TransformDirection(moveDirection);
controller.Move(globalDirection * Time.deltaTime * 5);
}
moveDirection.y -= 9.8f * Time.deltaTime;
if(controller.isGrounded)
{
moveDirection.y = 0;
}
}
}
【2020版】BattleOnline(基礎/全34回)
他のコースを見るテストキャラを動かす
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class TestMove : MonoBehaviour
{
private CharacterController controller;
private Vector3 moveDirection = Vector3.zero;
void Start()
{
controller = GetComponent<CharacterController>();
}
void Update()
{
moveDirection.z = Input.GetAxis("Vertical");
transform.Rotate(0, Input.GetAxis("Horizontal") * 6f, 0);
if(moveDirection.magnitude > 0.1f)
{
Vector3 globalDirection = transform.TransformDirection(moveDirection);
controller.Move(globalDirection * Time.deltaTime * 5);
}
moveDirection.y -= 9.8f * Time.deltaTime;
if(controller.isGrounded)
{
moveDirection.y = 0;
}
}
}
テストキャラを作成して動かす