Skip to content

Instantly share code, notes, and snippets.

@sirokm007n
Last active January 31, 2017 11:14
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save sirokm007n/411ce27b8e47bd4a90ef3adcc329e4a7 to your computer and use it in GitHub Desktop.
ブログ『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