I don´t know if is a bug or not, here is the problem: I have a CarStats_Playerscript and player damage script. the problem is when is showing the "warning!" text (GUI) when the player as 20% of health call CarStats_Player.showWarning = true; In the scene editor works fine, show the text gui "Warning!" But after "BUILD" and run is player as 20% of health the gui text "warning!" dont show?? Whats is the problem? static var showWarning : boolean = false; can not be call from other script??? See picture:
Here is the code: CarStats_Player: Code (csharp): private var activeWayPoint : WayPoint; //Strings text. var subMenuLoad : String = "MainMenu"; //Lap counter. var laps : int = 0; //Max of laps. var lapsMax : int = 3; var finalLap : int = 2; //sounds. var VoiceSoundGoal : AudioClip; var VoiceSoundLastLap : AudioClip; // Gui Styles. var LapGUIStyle : GUIStyle; var FinalFlagGUI : GUIStyle; var WarninglFlagGUI : GUIStyle; // GUi vectors. var WarningXeYPos = Vector2(10,600); var XeYPos = Vector2(5,35); var XeYPos2 = Vector2(5,65); var LapScoreXYPos = Vector2(5,95); var FlagPos = Vector2(5,350); // Booleans. private var showFlagWindow : boolean = false; private var showLastlapInfo : boolean = false; static var showWarning : boolean = false; // Strings, levels and number. var levelName : String = "LEVEL2"; var levelNumber : int = 2; function Start() { //activeWayPoint = WayPoint.start.next; activeWayPoint = WayPoint.start; } //var dist : float = 10; // Keeps track of when the player reaches the goal function OnTriggerEnter (triggerWaypoint : Collider) { // We allow the player to go through the waypoints only one after the other so he can't skip waypoints. if (activeWayPoint.collider == triggerWaypoint) { // When we reach the game might be finished! if (activeWayPoint == WayPoint.start) { //count laps. laps++; //If laps is the same as lapsMax, then do.... if (laps == lapsMax) { Savedata(); ReachedGoal(); } if (laps == finalLap) { AudioSource.PlayClipAtPoint(VoiceSoundLastLap, transform.position); showLastlapInfo = true; turnOfLastlapInfo(); } //if (Vector3.Distance(transform.position, transform.position) < dist) //{ //Debug.Log("Check Point!"); //} } activeWayPoint = activeWayPoint.next; } } // Save data function Savedata() { // add here your playerPrefs.SetInt //Example: //PlayerPrefs.SetInt("points",ColPoints.points); //PlayerPrefs.SetInt("kills",killCounter.curkills); //PlayerPrefs.SetInt(levelName, levelNumber); } // Load level or main menus. function LoadingLevel() { yield WaitForSeconds(5); Application.LoadLevel(subMenuLoad); } // I have reach the number of lap then stop function ReachedGoal() { // Stop driving if an AI car has completed the race! var aicar : AI_NOVO = GetComponent(AI_NOVO); if (aicar != null) aicar.enabled = false; LoadingLevel(); //enable the 3d text attach to the car //TextToShow.renderer.enabled = true; //check and slow the car regidbody in running and drag, to prevent the car moving alone. // show GUi flag. rigidbody.drag = 2.5; AudioSource.PlayClipAtPoint(VoiceSoundGoal, transform.position); showFlagWindow = true; } // turn boolean false if last lap GUI is true. function turnOfLastlapInfo() { yield WaitForSeconds (5); showLastlapInfo = false; } function OnGUI() { //GUI.color = Color.yellow; //GUI.Label(Rect(scorePos.x, scorePos.y,100,100), laps.ToString()); GUI.Button (new Rect(XeYPos.x, XeYPos.y, 150, 30),"Laps: " + laps, LapGUIStyle); GUI.Button (new Rect(XeYPos2.x, XeYPos2.y, 150, 30),"Total: " + lapsMax, LapGUIStyle); //show and enabled current boolean. // if finish the lap then do. if (showFlagWindow == true) { GUI.Button (new Rect(FlagPos.x, FlagPos.y, 250, 30),"Congratulations!", FinalFlagGUI); } // if is last lap then do if (showLastlapInfo == true) { GUI.Box (new Rect(FlagPos.x, FlagPos.y, 250, 30),"Last Lap!", FinalFlagGUI); } if (showWarning == true) { GUI.Box (new Rect(WarningXeYPos.x, WarningXeYPos.y, 250, 30),"WARNING!!", WarninglFlagGUI); } } @script ExecuteInEditMode() PlayerDamage: Line 52 , CarStats_Player.showWarning = true; Code (csharp): //in the object Enimigo.-RigidBody//com explosão var damage = 1; var health = 100; var explosion : Transform; var SmokeR : GameObject; var deadReplacement : Transform; var VoiceEnergylow : AudioClip; var WallCollisionSound : AudioClip; var PlayerHealthGUI : GUIStyle; var healthPos = Vector2(5,155); var CollisionStregth = 1; var AlertRed :boolean =false; var AlertNormal :boolean =true; var waterSplash : GameObject; function Awake () { SmokeR.particleEmitter.enabled = false; //add particles to the object directly. } function Update () { } function OnCollisionEnter(collision : Collision) { if (collision.relativeVelocity.magnitude > CollisionStregth) { if ((collision.gameObject.tag == "COM") || (collision.gameObject.tag == "WALL")) { if (health <= 0) // If Object health is Zero(0) then destroy. { Detonate (); var exp = Instantiate(explosion, gameObject.transform.position, Quaternion.identity); } // check if is low health then play sound and enabled smoke particles. else if (health == 20) { CarStats_Player.showWarning = true; AudioSource.PlayClipAtPoint(VoiceEnergylow, transform.position); SmokeR.particleEmitter.enabled = true; AlertRed = true; } health -= damage; } // Play wall colision sound if (collision.relativeVelocity.magnitude >= 0.1) { AudioSource.PlayClipAtPoint(WallCollisionSound, transform.position); } } } function OnTriggerEnter(trig : Collider) { if (trig.gameObject.tag == "water") { Instantiate (waterSplash, transform.position, Quaternion.identity); } } function Detonate () { // Destroy ourselves Destroy(gameObject); // Replace ourselves with the dead body if (deadReplacement) { var dead : Transform = Instantiate(deadReplacement, transform.position, transform.rotation); // Copy position rotation from the old hierarchy into the dead replacement CopyTransformsRecurse(transform, dead); } } static function CopyTransformsRecurse (src : Transform, dst : Transform) { dst.position = src.position; dst.rotation = src.rotation; for (var child : Transform in dst) { // Match the transform with the same name var curSrc = src.Find(child.name); if (curSrc) CopyTransformsRecurse(curSrc, child); } } function OnGUI() { //GUI.color = Color.cyan; //GUI.Label(Rect(healthPos.x, healthPos.y,100,100), health.ToString()); if (AlertRed) { GUI.color = Color.red; GUI.Button (new Rect(healthPos.x, healthPos.y, 150, 30),"HEALTH: " + health, PlayerHealthGUI); AlertNormal = false; } if (AlertNormal) { GUI.color = Color.green; GUI.Button (new Rect(healthPos.x, healthPos.y, 150, 30),"HEALTH: " + health, PlayerHealthGUI); } } @script ExecuteInEditMode()
if(health == 20) shouldn't it be if(health<=20){.......} You're saying that the warning sign should only be should when health is at 20 but not below 20.
Problem solved. The problem is in the inspector script setup , Warning Xe YPos = X >10, Y 600 to 250. fixed Y pos to 250. It was 600 show Warning text out of screen. Tks all of you.