Create a gist now

Instantly share code, notes, and snippets.

ブログ『Unity講座chap6』スクリプト『Time_limit.cs』
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class Time_limit : MonoBehaviour {
GameObject playerObj;
private float time;
public GameObject rankObj;
public Text timeLimit;
public Text rankLabel;
public int flag = 0;
// Use this for initialization
void Start () {
time = 60.0f;
playerObj = GameObject.Find( "SD_unitychan_humanoid" );
}
// Update is called once per frame
void Update () {
timeLimit.text = "制限時間:" + time + "";
if(time > 0.0){
time -= Time.deltaTime;
}else if (time <= 0.0) {
time = 0.0f;
//ランクスコア、テキスト(UI)非表示から表示に変更。
rankObj.SetActive (true);
//SD_unitychan_humanoidオブジェクトのControlスクリプトの変数などをこのスクリプト内で利用できるようにする。
Control scoreIncome = playerObj.GetComponent<Control>();
if(flag == 0){
//『scoreIncome.score』Controlスクリプトのscore変数を利用。
if(scoreIncome.score >= 0 && scoreIncome.score <= 1000){
rankLabel.text = "ランク:" + "D";
}else if(scoreIncome.score >= 1001 && scoreIncome.score <= 5000){
rankLabel.text = "ランク:" + "C";
}else if(scoreIncome.score >= 5001 && scoreIncome.score <= 7000){
rankLabel.text = "ランク:" + "B";
}else if(scoreIncome.score >= 7001 && scoreIncome.score <= 8000){
rankLabel.text = "ランク:" + "A";
}else if(scoreIncome.score >= 8001 && scoreIncome.score <= 9000){
rankLabel.text = "ランク:" + "S";
}else if(scoreIncome.score >= 9001 && scoreIncome.score <= 10000){
rankLabel.text = "ランク:" + "SS";
}else if(scoreIncome.score >= 10001){
rankLabel.text = "ランク:" + "";
}
flag = 1;
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment