Skip to content

Instantly share code, notes, and snippets.

@sirokm007n
Created February 8, 2017 10:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sirokm007n/3e41d4e6a8d25f769e621b9ef2fdea7d to your computer and use it in GitHub Desktop.
Save sirokm007n/3e41d4e6a8d25f769e621b9ef2fdea7d to your computer and use it in GitHub Desktop.
ブログ『Unity講座chap5』スクリプト『Control.cs』修正
using UnityEngine;
using System.Collections;
//**********//
using UnityEngine.UI;//UIをスクリプトから扱えるように
//**********//
public class Control : MonoBehaviour {
CharacterController control;
Vector3 move = Vector3.zero;
public float advanceSpeed;//左移動スピード値
public float backSpeed;//右移動スピード値
//**********//
public int score = 0;//スコア―格納変数
public Text scoreLabel;//スコア―を表示するテキストUI格納
//**********//
// 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;
}
}
//**********//
scoreLabel.text = "スコア―:" + score;//スコア―を表示
//**********//
}
//ボックス衝突処理
//**********//
void OnTriggerEnter(Collider box) {
if(box.gameObject.tag == "BoxWhite"){//白のボックスと衝突した場合の処理
score += 1000;
Destroy(box.gameObject);//衝突した白のボックス削除
}else if(box.gameObject.tag == "BoxRed"){//赤のボックスと衝突した場合の処理
score -= 2000;
Destroy(box.gameObject);//衝突した赤のボックス削除
}
}
//**********//
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment