I am making a game and I want to have it so it gives the player 10 more coins when they complete a level but my problem is that the amount of coins is in the player script and I’m trying to get it so when the checkpoint is reached it rewards coins. Top code is the player script and bottom code is the level completion script. (Also don’t mind the save system that is just a different part that I have completed)
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerCoins : MonoBehaviour
{
public int coins = 100;
public int level = 1;
public void SavePlayer()
{
SaveSystem.SavePlayer(this);
}
public void LoadPlayer ()
{
PlayerData data = SaveSystem.LoadPlayer();
level = data.level;
coins = data.coins;
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
public class LevelControler : MonoBehaviour
{
public int index;
public int level;
public int coins;
public string Level;
void OnTriggerEnter2D(Collider2D other)
{
if (other.CompareTag("Player"))
{
SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex + 1);
}
}
//SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex+1);
}