(スクリプト)
<レガシー版>
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class Password : MonoBehaviour
{
private InputField inputField;
public AudioClip successSound;
public AudioClip failedSound;
public GameObject sucessLabel;
public GameObject failedLabel;
void Start()
{
inputField = GetComponent<InputField>();
}
public void InputManager()
{
// プレーヤーが入力した文字情報を箱に入れる。
string str = inputField.text;
// パスワード成功
if(str == "aaa")
{
AudioSource.PlayClipAtPoint(successSound, Camera.main.transform.position);
sucessLabel.SetActive(true);
}
else // パスワード失敗
{
AudioSource.PlayClipAtPoint(failedSound, Camera.main.transform.position);
failedLabel.SetActive(true);
}
}
}
(スクリプト)
<TMP版>
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using TMPro;
public class PasswordTMP : MonoBehaviour
{
private TMP_InputField inputField;
public AudioClip successSound;
public AudioClip failedSound;
public GameObject sucessLabel;
public GameObject failedLabel;
void Start()
{
inputField = GetComponent<TMP_InputField>();
}
public void InputManager()
{
// プレーヤーが入力した文字情報を箱に入れる。
string str = inputField.text;
// パスワード成功
if (str == "aaa")
{
AudioSource.PlayClipAtPoint(successSound, Camera.main.transform.position);
sucessLabel.SetActive(true);
}
else // パスワード失敗
{
AudioSource.PlayClipAtPoint(failedSound, Camera.main.transform.position);
failedLabel.SetActive(true);
}
}
}
(設定)
(実行結果)