Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

237
Views
¿Cómo puedo cambiar el color si el valor es 25? Porque el valor "<= 50" está reemplazando al color amarillo del valor "25"

Mi "Salud <= 50" cambia de color si está por debajo de 50. Pero cuando llegue a 25 quiero cambiarlo a rojo. (Estoy en Unity, C#) Como etiquetado. Probé muchas combinaciones e investigué, pero no encontré ninguna respuesta. ¡Gracias por leer!

 using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; public class SomethingFunction : MonoBehaviour { [SerializeField] Text Informationsystem; public int Health 100; void Start() { TxtUI= GetComponent<Text>(); } void Update() { Test(); } public void Test() { if(health <= 50) { TxtUI.color = Color.yellow; } else if(health <= 25) { TxtUI.color = Color.red; } else if(health >= 50) { TxtUI.color = Color.white; } } }```
over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Investigue cómo funcionan las declaraciones if-else.

El problema aquí es que si, por ejemplo, la salud es 19: Entonces el color se establecerá en amarillo, porque 19<50.

Debido a la declaración else if, las otras comprobaciones no se ejecutan. Puede cambiar el orden de las declaraciones if-else o eliminar la parte else:

 if (health <= 25) { TxtUI.color = Color.red; } else if (health <= 50) { TxtUI.color = Color.yellow; } else if (health > 50) { TxtUI.color = Color.white; }
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!