一から始めるUnity入門/FX始めました

Unityを始めました。初心者向けの学習記事を書いていきます。

超基本 プレイヤーを動かすスクリプト

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Player : MonoBehaviour {

    public float walkForce = 300;
    private Rigidbody rb;

	// Use this for initialization
	void Start () {
        rb = GetComponent<Rigidbody>();
	}
	
	// Update is called once per frame
	void Update () {
        float x = Input.GetAxis("Horizontal") * walkForce * Time.deltaTime;
        float z = Input.GetAxis("Vertical") * walkForce * Time.deltaTime;
        rb.AddForce(new Vector3(x, 0, z));
	}
}