アニメーションの実装と同期




























アニメーション
using System.Collections; using System.Collections.Generic; using UnityEngine; using Photon.Pun; public class PlayerController : MonoBehaviourPunCallbacks { public float speed = 6.0f; public float jumpSpeed = 8.0f; public float gravity = 20.0f; private Vector3 moveDirection = Vector3.zero; private CharacterController controller; // ★追加(アニメーション) private Animator animator; void Start() { TryGetComponent(out controller); // ★追加(アニメーション) animator = GetComponent<Animator>(); } void Update() { if(photonView.IsMine) { if(controller.isGrounded) { var h = Input.GetAxis("Horizontal"); var v = Input.GetAxis("Vertical"); moveDirection = new Vector3(h, 0, v).normalized; // ★追加(アニメーション) animator.SetFloat("Front", moveDirection.z, 0.1f, Time.deltaTime); animator.SetFloat("Side", moveDirection.x, 0.1f, Time.deltaTime); moveDirection = transform.TransformDirection(moveDirection); moveDirection = moveDirection * speed; if(Input.GetKeyDown(KeyCode.Space)) { moveDirection.y = jumpSpeed; } } moveDirection.y = moveDirection.y - (gravity * Time.deltaTime); controller.Move(moveDirection * Time.deltaTime); } } }
C#








【2021版】BattleOnline(全37回)
他のコースを見る



























アニメーション
using System.Collections; using System.Collections.Generic; using UnityEngine; using Photon.Pun; public class PlayerController : MonoBehaviourPunCallbacks { public float speed = 6.0f; public float jumpSpeed = 8.0f; public float gravity = 20.0f; private Vector3 moveDirection = Vector3.zero; private CharacterController controller; // ★追加(アニメーション) private Animator animator; void Start() { TryGetComponent(out controller); // ★追加(アニメーション) animator = GetComponent<Animator>(); } void Update() { if(photonView.IsMine) { if(controller.isGrounded) { var h = Input.GetAxis("Horizontal"); var v = Input.GetAxis("Vertical"); moveDirection = new Vector3(h, 0, v).normalized; // ★追加(アニメーション) animator.SetFloat("Front", moveDirection.z, 0.1f, Time.deltaTime); animator.SetFloat("Side", moveDirection.x, 0.1f, Time.deltaTime); moveDirection = transform.TransformDirection(moveDirection); moveDirection = moveDirection * speed; if(Input.GetKeyDown(KeyCode.Space)) { moveDirection.y = jumpSpeed; } } moveDirection.y = moveDirection.y - (gravity * Time.deltaTime); controller.Move(moveDirection * Time.deltaTime); } } }
C#








アニメーションの実装と同期