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

162
Views
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 answers
Answer question

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 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!