@PeppyZee What exactly doensât work with your timer? Do you get odd outputs or doesnât the text update at all? And what type is your âKp_timerâ variable?
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.
Seems things I put in UpDate are not workingâŚ
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 string Kp_Code;
public int Kp_ErrorCount = 0;
private float a;
void Start()
{
a = Kp_timer;
Kp_CodeText.color = Kp_DefualtColor;
Kp_TimerText.color = Kp_DefualtColor;
Kp_CodeText.text = Kp_DefualtText;
//Cursor.SetCursor(MyCursor, MyhotSpot, MycursorMode);
}
void UpDate()
{
Kp_timer -= Time.deltaTime;
if(Kp_timer > 0)
{
Kp_TimerText.text= "Time Remaining : "+(int)Kp_timer;
Kp_TimerGauge.fillAmount = Kp_timer/a;
}
else{
Kp_TimerText.text = "DONE";
}
}
public void MyKeyCode (string Kp_Code)
{
if (Kp_CodeText.text == "CODE ?")
{
Kp_CodeText.text = "";
} else {
if(Kp_CodeText.text == "ERROR!")
{
Kp_CodeText.text = "";
}
}
Kp_CodeText.text = Kp_CodeText.text += Kp_Code;
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;
}
}
Is âUpDate()â a function which is called by you somewhere? Because if not, you probably want to write âUpdate()â (Unityâs âbuiltinâ function, which gets called every frame) instead⌠Note that C# is case sensitive, so mixing up lower- and upper-case will result in errors and/or not working code.
Haha yeah, those errors are the dumbest, but especially with Unityâs messages quite hard to find sometimes. Glad I could help, even though it wasnât even a ârealâ problemâŚ
And of course: Have fun programming your game !