プレイヤーを動かすためのスクリプト
それ用のスクリプトを作成する
Player>Inspector>AddComponent>NewScript
Name=PlayerController language=CSharp
Project欄のAssetsに追加されるので
Assets>右クリック>Create>Folder
できたフォルダをScriptsに名前変更

このPlayerControllerをダブルクリック
using UnityEngine;
using System.Collections;
public class PlayerController : MonoBehaviour {
public float speed = 3;
public float jumpPower = 6;
private Vector3 direction = Vector3.zero;
private CharacterController playerController;
// Use this for initialization
void Start () {
playerController = GetComponent
();
}
// Update is called once per frame
void Update () {
Debug.Log (direction);
if (playerController.isGrounded) {
float inputX = Input.GetAxis ("Horizontal");
float inputY = Input.GetAxis ("Vertical");
Vector3 inputDirection = new Vector3(inputX,0,inputY);
if (inputDirection.magnitude > 0.1) {
transform.LookAt (transform.position + inputDirection);
direction += transform.forward * speed;
}
if (Input.GetButton ("Jump")) {
Debug.Log ("ジャンプ");
//direction.y = transform.position.y;
direction.y += jumpPower;
}
}
direction.y += Physics.gravity.y * Time.deltaTime;
playerController.Move (direction * Time.deltaTime);
}
}
- 関連記事
-
YouTubeで動画を定期的に出しています。ご視聴いただけると嬉しいです。
Reon Labo
- 2016/08/18(木) 12:00:00|
- Unity
-
| トラックバック:0
-
| コメント:0