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.
i change the script and put killScore on PlayerPref and it will change in the main menu before play scene. thank you