I have two scripts one called score, which calculates the score then converts it to a string. The other script is called Score Multiplier, that updates the multiplier value in the score script when I pick up the multiplier object.
Score Script:
public float score = 0.0f;
public float defaultScore;
public float multiplierScore;
public float multiplierNum = 0;
public TextMeshProUGUI prefab;
void Update()
{
defaultScore = Time.deltaTime * 15;
multiplierScore = defaultScore *= multiplierNum;
score += multiplierScore;
prefab.text = ((int)score).ToString("0000000");
}
Score Multiplier script:
public GameObject pickupEffect;
public GameObject Score;
public float duration = 10f;
public void OnTriggerEnter2D(Collider2D other)
{
if (other.CompareTag("Player"))
{
PickUp();
}
}
public void PickUp()
{
Instantiate(pickupEffect, transform.position, Quaternion.identity);
Score multiplier = Score.GetComponent<Score>();
multiplier.multiplierNum = 1000;
Destroy(gameObject);
}
So when the player collides with the multiplier object the multiplierNum float value should update to 1000. Instead the value updates when I restart the game or when I die and respawn.
This is the respawn code in the player controller:
if (health <= 0)
{
SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex);
}
I just started using unity and coding about 4 days ago so please make your responses nood friendly.
Thanks.