Hello guys,how am i suppose to use “DontDestroyOnLoad” on an int because it is not a gameobject this is my code im trying to pass my score to the next scene.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;
public class PlayerController : MonoBehaviour {
public AudioSource cube;
public Text lifetext;
public Text counttext; // I want this to be in my next lvl
private int count; // I want this to be in my next lvl
private int life;
public int speed;
private Rigidbody rb3d;
// Use this for initialization
void Start () {
cube = GetComponent<AudioSource>();
rb3d = GetComponent<Rigidbody>();
SetCount();
SetLife();
life = 3;
lifetext.text = "LIFE : 3";
}
// Update is called once per frame
void FixedUpdate () {
float moveH = Input.GetAxis("Horizontal");
float moveV = Input.GetAxis("Vertical");
Vector3 movement = new Vector3(moveH, 0.0f, moveV);
rb3d.AddForce(movement * speed);
}
void OnTriggerEnter(Collider other)
{
if (other.gameObject.CompareTag("Cube"))
{
other.gameObject.SetActive(false);
cube.Play();
count = count + 1;
SetCount();
}
else if (other.gameObject.CompareTag("LVL"))
{
SceneManager.LoadScene("Main2");
}
else if (other.gameObject.CompareTag("U"))
{
SceneManager.LoadScene("Main");
life = life - 1;
SetLife();
}
}
void SetCount()
{
counttext.text = "SCORE : " + count.ToString();
}
void SetLife()
{
lifetext.text = "LIFE : " + life.ToString();
}
}