Maya->Unity2019(4)
スクリプトの適用
chair.csは削除します.スクリプトを選択し,chairの歯車のアイコンからremove componentを選択して削除します.
次に,回転に対応したスクリプトを作成する.ファイル名はmove1.cs
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
[RequireComponent(typeof(CharacterController))]
public class move1 : MonoBehaviour
{
public float speed = 3.0F;
public float rotateSpeed = 3.0F;
public float gravity = 10f;
public float jumpPower = 5;
private Vector3 moveDirection;
private CharacterController controller;
void Start()
{
// コンポーネントの取得
controller = GetComponent<CharacterController>();//キャラクターコントローラを取得し,変数contorllerに収納
}
void Update()
{
if (controller.isGrounded)//接地していれば
{
// 回転
transform.Rotate(0, Input.GetAxis("Horizontal") * rotateSpeed, 0);
// キャラクターのローカル空間での方向
moveDirection = transform.transform.forward * speed * Input.GetAxis("Vertical");
// ジャンプ
if (Input.GetButtonDown("Jump")) moveDirection.y = jumpPower;
}
else
{
// ジャンプ落下
moveDirection.y -= gravity * Time.deltaTime;
}
//移動させる
controller.Move(moveDirection * Time.deltaTime);
}
}
このスクリプトをイスのモデルにアサインします.
