Hello there. I have problem with this code.
It says NullReferenceException: Object reference not set to an instance of an object at line 25. In inspector I have attached script to game object. It works for player 1 but for player 2 not. If I manually increase score of second player it works but it seems like script is not getting score from script SimplePlatformController2. Can you help me?
using UnityEngine;
using System.Collections;
using UnityEngine.SceneManagement;
using UnityEngine.UI;
public class Score : MonoBehaviour {
private SimplePlatformController controll;
private SimplePlatformController2 controll2;
public int count11;
public int count22;
public Text WinText;
// Use this for initialization
void Awake () {
controll = GetComponent<SimplePlatformController>();
controll2 = GetComponent<SimplePlatformController2>();
}
// Update is called once per frame
void Update () {
count11 = controll.count1;
count22 = controll2.count2;
}
public void OnTriggerEnter2D(Collider2D other)
{
if (other.gameObject.CompareTag("Finish"))
{
other.gameObject.SetActive(false);
GameOver();
}
}
void GameOver()
{
if (count11 > count22)
{
SceneManager.LoadScene(3);
}
else if (count22 > count11)
{
SceneManager.LoadScene(4);
}
}
}