Hi, I am currently making a 2D game and I want it so that after every level I want to have the player be rewarded with 10 coins and I was hoping for help with this.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"))
{
PlayerCoins playercoins = other.gameObject.GetComponent<PlayerCoins>();
if (playercoins != null)
playercoins.coins += 10;
SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex + 1);
}
}
//SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex+1);
}
thats one of my codes
here's the otherusing 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;
}
}