Created
October 1, 2016 05:31
-
-
Save takoyakiroom/a674cb7d28d30d316a40401271a66547 to your computer and use it in GitHub Desktop.
ツールチップ
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 ControllerTooltips : MonoBehaviour{ | |
const float SHOW_DIST = 0.3f; // Tipsを表示する距離 | |
const float HIDE_TIME = 3.0f; // Tips消す時間 | |
GameObject eye; | |
GameObject trg; | |
GameObject pad; | |
bool show = true; | |
void Start () { | |
// 顔の位置 | |
eye = GameObject.Find("Camera (eye)"); | |
// ボタン | |
trg = gameObject.transform.FindChild("TriggerTooltip").gameObject; | |
pad = gameObject.transform.FindChild("TouchpadTooltip").gameObject; | |
// ゲーム開始後、コントローラ振動 | |
Invoke("Notice", HIDE_TIME); | |
} | |
void Update() | |
{ | |
// 顔とコントローラの距離 | |
float dist = Vector3.Distance(transform.position, eye.transform.position); | |
if (dist < SHOW_DIST) | |
{ | |
// 顔に近づけたら表示 | |
ShowTips(); | |
} | |
} | |
// Tips表示 | |
void ShowTips() | |
{ | |
if (show == true) | |
{ | |
return; | |
} | |
trg.SetActive(true); | |
pad.SetActive(true); | |
show = true; | |
// 非表示にする | |
Invoke("HideTips", HIDE_TIME); | |
} | |
// Tips非表示 | |
void HideTips() | |
{ | |
if(show == false) | |
{ | |
return; | |
} | |
trg.SetActive(false); | |
pad.SetActive(false); | |
show = false; | |
} | |
// プレイヤーに気付かせる | |
void Notice() | |
{ | |
// コントローラ振動 | |
Player player = GameObject.Find("[CameraRig]").GetComponent<Player>(); | |
player.Notice(); | |
// 表示消す | |
Invoke("HideTips", HIDE_TIME); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment