hi, i asked before and in theory i have to do this, so this code will save my coins right? but is wrong (where i put B)
CODE OF SCRIPT
Code (csharp):
-
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
-
- public class CoinsScore : MonoBehaviour
- {
- public static CoinsScore Coin;
- public GameObject ban;
- public void Awake()
- {
- PlayerPrefs.GetInt(“Player Score”);
- }
- public void OnTriggerEnter2D(Collider2D collider)
- {
- if (collider.CompareTag(“Player”))
- {
- GameController.instance.Coin();
- Coinz();
- Destroy(ban);
- }
- }
- public void Coinz()
- {
- PlayerPrefs.SetInt(“Player Score”, GameController.coin);
- PlayerPrefs.Save();
-
- }
- }
the code of Coin
Code (csharp):
-
-
- using System.Collections;
-
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.SceneManagement;
- using UnityEngine.UI;
-
- public class GameController : MonoBehaviour {
-
- public static GameController instance;
-
- public GameObject gameOverText;
-
- public bool gameOver;
- public float scrollSpeed = -1.5f;
-
- private int score;
- public static int coin;
- public Text scoreText;
- public Text cointext;
-
- private void Awake()
- {
- if(GameController.instance == null)
- {
- GameController.instance = this;
- }else if(GameController.instance != this)
- {
- Destroy(gameObject);
- Debug.LogWarning(“GameController ha sido instanciado por segunda vez. Esto no debería pasar.”);
- }
-
- }
-
-
- public void Coin()
-
- {
- coin++;
- Updateco();
- SoundSystem.instance.PlayCoin();
-
-
- }
-
- public void Updateco()
- {
- CoinsScore.Coin.Coinz();
- cointext.text = “” + coin;
-
-
-
- }
-
-
- public void BirdScored()
- {
- if (gameOver) return;
-
- score++;
- scoreText.text = "Score: " + score;
-
- }
-
- public void BirdDie()
- {
- gameOverText.SetActive(true);
- gameOver = true;
- }
-
- private void OnDestroy()
- {
- if(GameController.instance == this)
- {
- GameController.instance = null;
- }
- }
- }
-