Last active
January 31, 2017 11:14
Star
You must be signed in to star a gist
ブログ『Unity講座chap2』スクリプト『Control.cs』
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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