テストキャラを作成して動かす
![F002e05d 9201 4879 8f89 21a1a2aba5dc](https://codegenius.org/uploads/slide/image/8458/f002e05d-9201-4879-8f89-21a1a2aba5dc.jpeg)
![B86f2d2a 9445 43bc b33d 75f0a088ed44](https://codegenius.org/uploads/slide/image/8459/b86f2d2a-9445-43bc-b33d-75f0a088ed44.jpeg)
![2952ea22 2572 497e aedf 16a36af75ee0](https://codegenius.org/uploads/slide/image/8460/2952ea22-2572-497e-aedf-16a36af75ee0.jpeg)
![340d6bad d731 4aef a76e 023cdc49c3c9](https://codegenius.org/uploads/slide/image/8461/340d6bad-d731-4aef-a76e-023cdc49c3c9.jpeg)
![63d07d4c 1daf 4643 9a01 d3fede48f53a](https://codegenius.org/uploads/slide/image/8462/63d07d4c-1daf-4643-9a01-d3fede48f53a.jpeg)
![2190d19d e6ed 409e 9baa cbcfcdf3e0fe](https://codegenius.org/uploads/slide/image/8463/2190d19d-e6ed-409e-9baa-cbcfcdf3e0fe.jpeg)
![Ceefd515 3352 4a03 851e ed41ecb401ba](https://codegenius.org/uploads/slide/image/8464/ceefd515-3352-4a03-851e-ed41ecb401ba.jpeg)
キャラを動かす
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;
}
}
}
![2f25ef0b deba 4bca 9049 b8a867ce3f5d](https://codegenius.org/uploads/slide/image/8465/2f25ef0b-deba-4bca-9049-b8a867ce3f5d.jpeg)
【2021版】BattleOnline(全37回)
他のコースを見る![F002e05d 9201 4879 8f89 21a1a2aba5dc](https://codegenius.org/uploads/slide/image/8458/f002e05d-9201-4879-8f89-21a1a2aba5dc.jpeg)
![B86f2d2a 9445 43bc b33d 75f0a088ed44](https://codegenius.org/uploads/slide/image/8459/b86f2d2a-9445-43bc-b33d-75f0a088ed44.jpeg)
![2952ea22 2572 497e aedf 16a36af75ee0](https://codegenius.org/uploads/slide/image/8460/2952ea22-2572-497e-aedf-16a36af75ee0.jpeg)
![340d6bad d731 4aef a76e 023cdc49c3c9](https://codegenius.org/uploads/slide/image/8461/340d6bad-d731-4aef-a76e-023cdc49c3c9.jpeg)
![63d07d4c 1daf 4643 9a01 d3fede48f53a](https://codegenius.org/uploads/slide/image/8462/63d07d4c-1daf-4643-9a01-d3fede48f53a.jpeg)
![2190d19d e6ed 409e 9baa cbcfcdf3e0fe](https://codegenius.org/uploads/slide/image/8463/2190d19d-e6ed-409e-9baa-cbcfcdf3e0fe.jpeg)
![Ceefd515 3352 4a03 851e ed41ecb401ba](https://codegenius.org/uploads/slide/image/8464/ceefd515-3352-4a03-851e-ed41ecb401ba.jpeg)
キャラを動かす
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;
}
}
}
![2f25ef0b deba 4bca 9049 b8a867ce3f5d](https://codegenius.org/uploads/slide/image/8465/2f25ef0b-deba-4bca-9049-b8a867ce3f5d.jpeg)
テストキャラを作成して動かす