テストキャラを作成して動かす
キャラを動かす
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 * 5f);
}
moveDirection.y -= 3f * Time.deltaTime;
if(controller.isGrounded)
{
moveDirection.y = 0;
}
}
}
【2021版】BattleOnline(全37回)
他のコースを見るキャラを動かす
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 * 5f);
}
moveDirection.y -= 3f * Time.deltaTime;
if(controller.isGrounded)
{
moveDirection.y = 0;
}
}
}
テストキャラを作成して動かす