Last active
February 16, 2017 07:31
-
-
Save sirokm007n/258df607b8dc73ffc1b64d03afe48048 to your computer and use it in GitHub Desktop.
ブログ『Unity講座chap6』スクリプト『Time_limit.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; | |
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