Kp_TimerText is not showing the Timer Value…
Kp_GuageImage is not charing its fill amount to represent timer.
Kp_KeyPad is being Disabled on code failure where I need just its Keys (buttons) to be disabled.
I cant seem to get these things working, Every thing else works as it should. With the exception of the timer as I am not sure if it is actually functioning at all.
See Script Notations for more info… Any suggestions or examples would be appreciated…
Basically its a script that controls a Code Entry KeyPad.
using UnityEngine;
using UnityEngine.UI;
using System.Collections;
public class UI_Control : MonoBehaviour
{
public GameObject Kp_SecurityCenter;
public Canvas Kp_KeyPad;
public Text Kp_CodeText;
public Text Kp_TimerText;
public Image Kp_TimerGauge;
public string Kp_DefualtText = "CODE ?";
public Color Kp_DefualtColor = new Vector4(0.0F, 255, 0.0F, 1);
public Color Kp_AlarmColor = new Vector4(255F, 0.0F, 0.0F, 1);
public bool IsActive = true;
public bool IsSelected = true;
public bool IsPlayerIn = true;
public bool IsHackable = true;
public bool IsLocked = true;
public bool IsLockable = true;
public bool IsReLock = false;
public string uPassCode = "123";
public string lPassCode= "321";
public bool IsTimed = true;
public float Kp_timer = 10.0f;
public AudioClip S_Button;
public AudioClip Su_lock;
public AudioClip S_Lock;
public AudioClip Se_Lock;
public AudioClip Alarm;
public Texture2D MyCursor;
public Vector2 MyhotSpot = Vector2.zero;
public CursorMode MycursorMode = CursorMode.Auto;
private float a;
private string MyCode;
public int Kp_ErrorCount = 0;
void Start()
{
Kp_CodeText.color = Kp_DefualtColor;
Kp_TimerText.color = Kp_DefualtColor;
Cursor.SetCursor(MyCursor, MyhotSpot, MycursorMode);
}
void UpDate()
{
/* Was trying this to see if anything would happen, and nothing...
a = a + 0.01f;
Kp_TimerGauge.fillAmount = a;
*/
if (IsTimed && IsActive && IsLocked)
{
Kp_timer -= Time.deltaTime;
if (Kp_timer < 0)
{
Kp_timer = 0;
}
float seconds = Kp_timer % 60;
float minutes = Kp_timer / 60;
// Kp_TimerText is not showing time.
Kp_TimerText.text = minutes + ":" + seconds;
// Code to change Kp-GuageImage fill amount here...
}
}
public void MyKeyCode (string MyCode)
{
if (Kp_CodeText.text == "CODE ?")
{
Kp_CodeText.text = "";
} else {
if(Kp_CodeText.text == "ERROR!")
{
Kp_CodeText.text = "";
}
}
Kp_CodeText.text = Kp_CodeText.text += MyCode;
print ("Key");
}
public void Kp_Check()
{
if (Kp_CodeText.text == uPassCode)
{
Kp_CodeText.text = "UNLOCKED";
IsLocked=false;
AudioSource.PlayClipAtPoint (Su_lock, (new Vector3 (0, 0, 0)));
} else
{
if (Kp_CodeText.text == lPassCode)
{
Kp_CodeText.text = "LOCKED";
IsLocked=true;
AudioSource.PlayClipAtPoint (S_Lock, (new Vector3 (0, 0, 0)));
}else{
Kp_CodeText.color=Kp_AlarmColor;
Kp_CodeText.text = "ERROR!";
AudioSource.PlayClipAtPoint (Alarm, (new Vector3 (0, 0, 0)));
// Disables panel and not buttons on it.
Kp_KeyPad.enabled = false;
StartCoroutine("ResTime");
}
}
}
public void Kp_Clear()
{
print ("Cancel");
Kp_CodeText.text = Kp_DefualtText;
Kp_CodeText.color = Kp_DefualtColor;
}
public void Kp_Exit()
{
print ("Exit");
}
IEnumerator ResTime()
{
yield return new WaitForSeconds(2);
if(IsReLock)
{
IsLocked=true;
}
Kp_ErrorCount = Kp_ErrorCount + 1;
Kp_CodeText.color = Kp_DefualtColor;
Kp_CodeText.text = Kp_DefualtText;
Kp_KeyPad.enabled = true;
}
}