Create a gist now

Instantly share code, notes, and snippets.

ブログ『Unity講座chap2』スクリプト『Control.cs』
using UnityEngine;
using System.Collections;
public class Control : MonoBehaviour {
CharacterController control;
Vector3 move = Vector3.zero;
public float advanceSpeed;//左移動スピード値
public float backSpeed;//右移動スピード値
// Use this for initialization
void Start () {
control = GetComponent<CharacterController> ();
}
// Update is called once per frame
void Update () {
if (control.isGrounded) {
if (Input.GetMouseButton (0)) {//マウス左クリック中『左移動』
move.z += advanceSpeed * Time.deltaTime;
control.Move (move * Time.deltaTime);
} else {//離される『停止』
move.z = 0;
}
if (Input.GetMouseButton (1)) {//マウス右クリック中『右移動』
move.z -= backSpeed * Time.deltaTime;
control.Move (move * Time.deltaTime);
} else {//離される『停止』
move.z = 0;
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment