Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

164
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda