Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

165
Vistas
value inside switch wont change, unity

i have switch and some case. this code only work on first line. it need to reload twice so the rest of the code would work. it change enemy damage at first but it need to reload twice to change killScore. anyone know why?

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using TMPro;


public class Difficulty : MonoBehaviour
{
    public int difficulty;
    public ammo enemyDamage;
    public enemy enemy1;
    public enemy enemy2;
    //public enemy enemy2;
    public TextMeshProUGUI diff;
    // Start is called before the first frame update
    void Awake()
    {
        difficulty = PlayerPrefs.GetInt("Difficulty");
        diff.text = PlayerPrefs.GetInt("Difficulty").ToString();
    
        switch(PlayerPrefs.GetInt("Difficulty"))
        {
            case 0:
                difficulties(3,100);
                break;
            case 1:
                difficulties(5,200);
                break;
            case 2:
                difficulties(7,300);
                break;
        }
        
        Debug.Log("kill score : " + enemy1.killScore);
        Debug.Log("difficulty : " + difficulty);

    }

    // Update is called once per frame
    void Update()
    {
    }

    void difficulties(int a, int b)
    {
        enemyDamage.enemyDamage = a;
        enemy1.killScore = b;
        enemy2.killScore = b;
    }
}

it change value on the prefab but the prefab i put on the scene doesnt.

over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

i change the script and put killScore on PlayerPref and it will change in the main menu before play scene. thank you

over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda