Hey Guys,
I just started a huge Project and got some problems with the first game. In the editor everything works well but after i build the game sends Null reference errors in a specific gamemode. And crashs within Player3.
Hope Somebody can help me:
Code Follow The Line:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class FollowTheLine : MonoBehaviour
{
public Transform[] waypoints;
[SerializeField] public float moveSpeed = 1f;
[HideInInspector] public int waypointIndex = 0;
public bool moveAllowed = false;
private void Start()
{
transform.position = waypoints[waypointIndex].transform.position;
}
public void Update()
{
if (moveAllowed)
Move();
transform.position = waypoints[waypointIndex].transform.position;
}
public void Move()
{
if (waypointIndex <=waypoints.Length - 1)
{
transform.position = Vector2.MoveTowards(transform.position,
waypoints[waypointIndex].transform.position,
moveSpeed * Time.deltaTime);
if (transform.position == waypoints[waypointIndex].transform.position)
{
waypointIndex += 1;
}
}
}
}
The LadderControll skript:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class LadderControl : MonoBehaviour
{
public static GameObject player1MoveText, player2MoveText, player3MoveText, player4MoveText, player5MoveText, player6MoveText, player7MoveText, player8MoveText, player12MoveText;
public static GameObject player1, player2, player3, player4, player5, player6, player7, player8, player12;
public static int nofPlayers;
public static int Player1;
public static int Player2;
public static int Player3;
public static int Player4;
public static int Player5;
public static int Player6;
public static int Player7;
public static int Player8;
public static int Player12;
public static int diceSideThrown = 0;
public static int player1StartWaypoint = 0;
public static int player2StartWaypoint = 0;
public static int player3StartWaypoint = 0;
public static int player4StartWaypoint = 0;
public static int player5StartWaypoint = 0;
public static int player6StartWaypoint = 0;
public static int player7StartWaypoint = 0;
public static int player8StartWaypoint = 0;
public static int player12StartWaypoint = 0;
public static bool gameOver = false;
public void Start()
{
diceSideThrown = 0;
player1StartWaypoint = 0;
player2StartWaypoint = 0;
player2StartWaypoint = 0;
player3StartWaypoint = 0;
player4StartWaypoint = 0;
player5StartWaypoint = 0;
player6StartWaypoint = 0;
player7StartWaypoint = 0;
player8StartWaypoint = 0;
player12StartWaypoint = 0;
gameOver = false;
//Objekte finden
player1MoveText = GameObject.Find("P1Move");
player2MoveText = GameObject.Find("P2Move");
player3MoveText = GameObject.Find("P3Move");
player4MoveText = GameObject.Find("P4Move");
player5MoveText = GameObject.Find("P5Move");
player6MoveText = GameObject.Find("P6Move");
player7MoveText = GameObject.Find("P7Move");
player8MoveText = GameObject.Find("P8Move");
player12MoveText = GameObject.Find("P9Move");
player1 = GameObject.Find("Player1");
player2 = GameObject.Find("Player2");
player3 = GameObject.Find("Player3");
player4 = GameObject.Find("Player4");
player5 = GameObject.Find("Player5");
player6 = GameObject.Find("Player6");
player7 = GameObject.Find("Player7");
player8 = GameObject.Find("Player8");
player12 = GameObject.Find("Player12");
player1.GetComponent<FollowTheLine>().moveAllowed = false;
player2.GetComponent<FollowTheLine>().moveAllowed = false;
player3.GetComponent<FollowTheLine>().moveAllowed = false;
player4.GetComponent<FollowTheLine>().moveAllowed = false;
player5.GetComponent<FollowTheLine>().moveAllowed = false;
player6.GetComponent<FollowTheLine>().moveAllowed = false;
player7.GetComponent<FollowTheLine>().moveAllowed = false;
player8.GetComponent<FollowTheLine>().moveAllowed = false;
player12.GetComponent<FollowTheLine>().moveAllowed = false;
//player10.GetComponent<FollowTheLine>().moveAllowed = false;
//whoWinsTextShadow.gameObject.SetActive(false);
//player1MoveText.gameObject.SetActive(true);
//player2MoveText.gameObject.SetActive(false);
}
public void Update()
{
if (RollDice.whosTurn == 1)
{
player1MoveText.gameObject.SetActive(true);
player2MoveText.gameObject.SetActive(false);
player3MoveText.gameObject.SetActive(false);
player4MoveText.gameObject.SetActive(false);
player5MoveText.gameObject.SetActive(false);
player6MoveText.gameObject.SetActive(false);
player7MoveText.gameObject.SetActive(false);
player8MoveText.gameObject.SetActive(false);
player12MoveText.gameObject.SetActive(false);
//player10MoveText.gameObject.SetActive(false);
}
else if (RollDice.whosTurn == 2)
{
player1MoveText.gameObject.SetActive(false);
player2MoveText.gameObject.SetActive(true);
player3MoveText.gameObject.SetActive(false);
player4MoveText.gameObject.SetActive(false);
player5MoveText.gameObject.SetActive(false);
player6MoveText.gameObject.SetActive(false);
player7MoveText.gameObject.SetActive(false);
player8MoveText.gameObject.SetActive(false);
player12MoveText.gameObject.SetActive(false);
//player10MoveText.gameObject.SetActive(false);
}
else if (RollDice.whosTurn == 3)
{
player1MoveText.gameObject.SetActive(false);
player2MoveText.gameObject.SetActive(false);
player3MoveText.gameObject.SetActive(true);
player4MoveText.gameObject.SetActive(false);
player5MoveText.gameObject.SetActive(false);
player6MoveText.gameObject.SetActive(false);
player7MoveText.gameObject.SetActive(false);
player8MoveText.gameObject.SetActive(false);
player12MoveText.gameObject.SetActive(false);
//player10MoveText.gameObject.SetActive(false);
}
else if (RollDice.whosTurn == 4)
{
player1MoveText.gameObject.SetActive(false);
player2MoveText.gameObject.SetActive(false);
player3MoveText.gameObject.SetActive(false);
player4MoveText.gameObject.SetActive(true);
player5MoveText.gameObject.SetActive(false);
player6MoveText.gameObject.SetActive(false);
player7MoveText.gameObject.SetActive(false);
player8MoveText.gameObject.SetActive(false);
player12MoveText.gameObject.SetActive(false);
//player10MoveText.gameObject.SetActive(false);
}
else if (RollDice.whosTurn == 5)
{
player1MoveText.gameObject.SetActive(false);
player2MoveText.gameObject.SetActive(false);
player3MoveText.gameObject.SetActive(false);
player4MoveText.gameObject.SetActive(false);
player5MoveText.gameObject.SetActive(true);
player6MoveText.gameObject.SetActive(false);
player7MoveText.gameObject.SetActive(false);
player8MoveText.gameObject.SetActive(false);
player12MoveText.gameObject.SetActive(false);
//player10MoveText.gameObject.SetActive(false);
}
else if (RollDice.whosTurn == 6)
{
player1MoveText.gameObject.SetActive(false);
player2MoveText.gameObject.SetActive(false);
player3MoveText.gameObject.SetActive(false);
player4MoveText.gameObject.SetActive(false);
player5MoveText.gameObject.SetActive(false);
player6MoveText.gameObject.SetActive(true);
player7MoveText.gameObject.SetActive(false);
player8MoveText.gameObject.SetActive(false);
player12MoveText.gameObject.SetActive(false);
//player10MoveText.gameObject.SetActive(false);
}
else if (RollDice.whosTurn == 7)
{
player1MoveText.gameObject.SetActive(false);
player2MoveText.gameObject.SetActive(false);
player3MoveText.gameObject.SetActive(false);
player4MoveText.gameObject.SetActive(false);
player5MoveText.gameObject.SetActive(false);
player6MoveText.gameObject.SetActive(false);
player7MoveText.gameObject.SetActive(true);
player8MoveText.gameObject.SetActive(false);
player12MoveText.gameObject.SetActive(false);
//player10MoveText.gameObject.SetActive(false);
}
else if (RollDice.whosTurn == 8)
{
player1MoveText.gameObject.SetActive(false);
player2MoveText.gameObject.SetActive(false);
player3MoveText.gameObject.SetActive(false);
player4MoveText.gameObject.SetActive(false);
player5MoveText.gameObject.SetActive(false);
player6MoveText.gameObject.SetActive(false);
player7MoveText.gameObject.SetActive(false);
player8MoveText.gameObject.SetActive(true);
player12MoveText.gameObject.SetActive(false);
//player10MoveText.gameObject.SetActive(false);
}
else if (RollDice.whosTurn == 9)
{
player1MoveText.gameObject.SetActive(false);
player2MoveText.gameObject.SetActive(false);
player3MoveText.gameObject.SetActive(false);
player4MoveText.gameObject.SetActive(false);
player5MoveText.gameObject.SetActive(false);
player6MoveText.gameObject.SetActive(false);
player7MoveText.gameObject.SetActive(false);
player8MoveText.gameObject.SetActive(false);
player12MoveText.gameObject.SetActive(true);
//player10MoveText.gameObject.SetActive(false);
}
//else if (RollDice.whosTurn == 10)
//{
// player1MoveText.gameObject.SetActive(false);
// player2MoveText.gameObject.SetActive(false);
// player3MoveText.gameObject.SetActive(false);
// player4MoveText.gameObject.SetActive(false);
// player5MoveText.gameObject.SetActive(false);
// player6MoveText.gameObject.SetActive(false);
// player7MoveText.gameObject.SetActive(false);
// player8MoveText.gameObject.SetActive(false);
// player9MoveText.gameObject.SetActive(false);
// player10MoveText.gameObject.SetActive(true);
//}
//Player 1
if (player1.GetComponent<FollowTheLine>().waypointIndex >
player1StartWaypoint + diceSideThrown)
{
if (player1StartWaypoint + diceSideThrown == 15)
{
player1.GetComponent<FollowTheLine>().transform.position = player1.GetComponent<FollowTheLine>().waypoints[1].transform.position;
player1.GetComponent<FollowTheLine>().waypointIndex = 1;
player1.GetComponent<FollowTheLine>().waypointIndex += 1;
MovePlayer(1);
}
if (player1StartWaypoint + diceSideThrown == 22)
{
player1.GetComponent<FollowTheLine>().transform.position = player1.GetComponent<FollowTheLine>().waypoints[12].transform.position;
player1.GetComponent<FollowTheLine>().waypointIndex = 12;
player1.GetComponent<FollowTheLine>().waypointIndex += 1;
MovePlayer(1);
}
if (player1StartWaypoint + diceSideThrown == 33)
{
player1.GetComponent<FollowTheLine>().transform.position = player1.GetComponent<FollowTheLine>().waypoints[19].transform.position;
player1.GetComponent<FollowTheLine>().waypointIndex = 19;
player1.GetComponent<FollowTheLine>().waypointIndex += 1;
MovePlayer(1);
}
player1.GetComponent<FollowTheLine>().moveAllowed = false;
player1StartWaypoint = player1.GetComponent<FollowTheLine>().waypointIndex - 1;
}
//Player 2
else if (player2.GetComponent<FollowTheLine>().waypointIndex >
player2StartWaypoint + diceSideThrown)
{
if (player2StartWaypoint + diceSideThrown == 15)
{
player2.GetComponent<FollowTheLine>().transform.position = player2.GetComponent<FollowTheLine>().waypoints[1].transform.position;
player2.GetComponent<FollowTheLine>().waypointIndex = 1;
player2.GetComponent<FollowTheLine>().waypointIndex += 1;
MovePlayer(2);
}
if (player2StartWaypoint + diceSideThrown == 22)
{
player2.GetComponent<FollowTheLine>().transform.position = player2.GetComponent<FollowTheLine>().waypoints[12].transform.position;
player2.GetComponent<FollowTheLine>().waypointIndex = 12;
player2.GetComponent<FollowTheLine>().waypointIndex += 1;
MovePlayer(2);
}
if (player2StartWaypoint + diceSideThrown == 33)
{
player2.GetComponent<FollowTheLine>().transform.position = player2.GetComponent<FollowTheLine>().waypoints[19].transform.position;
player2.GetComponent<FollowTheLine>().waypointIndex = 19;
player2.GetComponent<FollowTheLine>().waypointIndex += 1;
MovePlayer(2);
}
player2.GetComponent<FollowTheLine>().moveAllowed = false;
player2StartWaypoint = player2.GetComponent<FollowTheLine>().waypointIndex - 1;
}
//Player 3
else if (player3.GetComponent<FollowTheLine>().waypointIndex >
player3StartWaypoint + diceSideThrown)
{
if (player3StartWaypoint + diceSideThrown == 15)
{
player3.GetComponent<FollowTheLine>().transform.position = player3.GetComponent<FollowTheLine>().waypoints[1].transform.position;
player3.GetComponent<FollowTheLine>().waypointIndex = 1;
player3.GetComponent<FollowTheLine>().waypointIndex += 1;
MovePlayer(3);
}
if (player3StartWaypoint + diceSideThrown == 22)
{
player3.GetComponent<FollowTheLine>().transform.position = player3.GetComponent<FollowTheLine>().waypoints[12].transform.position;
player3.GetComponent<FollowTheLine>().waypointIndex = 12;
player3.GetComponent<FollowTheLine>().waypointIndex += 1;
MovePlayer(3);
}
if (player3StartWaypoint + diceSideThrown == 33)
{
player3.GetComponent<FollowTheLine>().transform.position = player3.GetComponent<FollowTheLine>().waypoints[19].transform.position;
player3.GetComponent<FollowTheLine>().waypointIndex = 19;
player3.GetComponent<FollowTheLine>().waypointIndex += 1;
MovePlayer(3);
}
player3.GetComponent<FollowTheLine>().moveAllowed = false;
player3StartWaypoint = player3.GetComponent<FollowTheLine>().waypointIndex - 1;
}
//Player 4
else if (player4.GetComponent<FollowTheLine>().waypointIndex >
player4StartWaypoint + diceSideThrown)
{
if (player4StartWaypoint + diceSideThrown == 15)
{
player4.GetComponent<FollowTheLine>().transform.position = player4.GetComponent<FollowTheLine>().waypoints[1].transform.position;
player4.GetComponent<FollowTheLine>().waypointIndex = 1;
player4.GetComponent<FollowTheLine>().waypointIndex += 1;
MovePlayer(4);
}
if (player4StartWaypoint + diceSideThrown == 22)
{
player4.GetComponent<FollowTheLine>().transform.position = player4.GetComponent<FollowTheLine>().waypoints[12].transform.position;
player4.GetComponent<FollowTheLine>().waypointIndex = 12;
player4.GetComponent<FollowTheLine>().waypointIndex += 1;
MovePlayer(4);
}
if (player4StartWaypoint + diceSideThrown == 33)
{
player4.GetComponent<FollowTheLine>().transform.position = player4.GetComponent<FollowTheLine>().waypoints[19].transform.position;
player4.GetComponent<FollowTheLine>().waypointIndex = 19;
player4.GetComponent<FollowTheLine>().waypointIndex += 1;
MovePlayer(4);
}
player4.GetComponent<FollowTheLine>().moveAllowed = false;
player4StartWaypoint = player4.GetComponent<FollowTheLine>().waypointIndex - 1;
}
//Player 5
else if (player5.GetComponent<FollowTheLine>().waypointIndex >
player5StartWaypoint + diceSideThrown)
{
if (player5StartWaypoint + diceSideThrown == 15)
{
player5.GetComponent<FollowTheLine>().transform.position = player5.GetComponent<FollowTheLine>().waypoints[1].transform.position;
player5.GetComponent<FollowTheLine>().waypointIndex = 1;
player5.GetComponent<FollowTheLine>().waypointIndex += 1;
MovePlayer(5);
}
if (player5StartWaypoint + diceSideThrown == 22)
{
player5.GetComponent<FollowTheLine>().transform.position = player5.GetComponent<FollowTheLine>().waypoints[12].transform.position;
player5.GetComponent<FollowTheLine>().waypointIndex = 12;
player5.GetComponent<FollowTheLine>().waypointIndex += 1;
MovePlayer(5);
}
if (player5StartWaypoint + diceSideThrown == 33)
{
player5.GetComponent<FollowTheLine>().transform.position = player5.GetComponent<FollowTheLine>().waypoints[19].transform.position;
player5.GetComponent<FollowTheLine>().waypointIndex = 19;
player5.GetComponent<FollowTheLine>().waypointIndex += 1;
MovePlayer(5);
}
player5.GetComponent<FollowTheLine>().moveAllowed = false;
player5StartWaypoint = player5.GetComponent<FollowTheLine>().waypointIndex - 1;
}
//Player 6
else if (player6.GetComponent<FollowTheLine>().waypointIndex >
player6StartWaypoint + diceSideThrown)
{
if (player6StartWaypoint + diceSideThrown == 15)
{
player6.GetComponent<FollowTheLine>().transform.position = player6.GetComponent<FollowTheLine>().waypoints[1].transform.position;
player6.GetComponent<FollowTheLine>().waypointIndex = 1;
player6.GetComponent<FollowTheLine>().waypointIndex += 1;
MovePlayer(6);
}
if (player6StartWaypoint + diceSideThrown == 22)
{
player6.GetComponent<FollowTheLine>().transform.position = player6.GetComponent<FollowTheLine>().waypoints[12].transform.position;
player6.GetComponent<FollowTheLine>().waypointIndex = 12;
player6.GetComponent<FollowTheLine>().waypointIndex += 1;
MovePlayer(6);
}
if (player6StartWaypoint + diceSideThrown == 33)
{
player6.GetComponent<FollowTheLine>().transform.position = player6.GetComponent<FollowTheLine>().waypoints[19].transform.position;
player6.GetComponent<FollowTheLine>().waypointIndex = 19;
player6.GetComponent<FollowTheLine>().waypointIndex += 1;
MovePlayer(6);
}
player6.GetComponent<FollowTheLine>().moveAllowed = false;
player6StartWaypoint = player6.GetComponent<FollowTheLine>().waypointIndex - 1;
}
//Player 7
else if (player7.GetComponent<FollowTheLine>().waypointIndex >
player7StartWaypoint + diceSideThrown)
{
if (player7StartWaypoint + diceSideThrown == 15)
{
player7.GetComponent<FollowTheLine>().transform.position = player7.GetComponent<FollowTheLine>().waypoints[1].transform.position;
player7.GetComponent<FollowTheLine>().waypointIndex = 1;
player7.GetComponent<FollowTheLine>().waypointIndex += 1;
MovePlayer(7);
}
if (player7StartWaypoint + diceSideThrown == 22)
{
player7.GetComponent<FollowTheLine>().transform.position = player7.GetComponent<FollowTheLine>().waypoints[12].transform.position;
player7.GetComponent<FollowTheLine>().waypointIndex = 12;
player7.GetComponent<FollowTheLine>().waypointIndex += 1;
MovePlayer(7);
}
if (player7StartWaypoint + diceSideThrown == 33)
{
player7.GetComponent<FollowTheLine>().transform.position = player7.GetComponent<FollowTheLine>().waypoints[19].transform.position;
player7.GetComponent<FollowTheLine>().waypointIndex = 19;
player7.GetComponent<FollowTheLine>().waypointIndex += 1;
MovePlayer(7);
}
player7.GetComponent<FollowTheLine>().moveAllowed = false;
player7StartWaypoint = player7.GetComponent<FollowTheLine>().waypointIndex - 1;
}
//Player 8
else if (player8.GetComponent<FollowTheLine>().waypointIndex >
player8StartWaypoint + diceSideThrown)
{
if (player8StartWaypoint + diceSideThrown == 15)
{
player8.GetComponent<FollowTheLine>().transform.position = player8.GetComponent<FollowTheLine>().waypoints[1].transform.position;
player8.GetComponent<FollowTheLine>().waypointIndex = 1;
player8.GetComponent<FollowTheLine>().waypointIndex += 1;
MovePlayer(8);
}
if (player8StartWaypoint + diceSideThrown == 22)
{
player8.GetComponent<FollowTheLine>().transform.position = player8.GetComponent<FollowTheLine>().waypoints[12].transform.position;
player8.GetComponent<FollowTheLine>().waypointIndex = 12;
player8.GetComponent<FollowTheLine>().waypointIndex += 1;
MovePlayer(8);
}
if (player8StartWaypoint + diceSideThrown == 33)
{
player8.GetComponent<FollowTheLine>().transform.position = player8.GetComponent<FollowTheLine>().waypoints[19].transform.position;
player8.GetComponent<FollowTheLine>().waypointIndex = 19;
player8.GetComponent<FollowTheLine>().waypointIndex += 1;
MovePlayer(8);
}
player8.GetComponent<FollowTheLine>().moveAllowed = false;
player8StartWaypoint = player8.GetComponent<FollowTheLine>().waypointIndex - 1;
}
//Player 9
else if (player12.GetComponent<FollowTheLine>().waypointIndex >
player12StartWaypoint + diceSideThrown)
{
if (player12StartWaypoint + diceSideThrown == 15)
{
player12.GetComponent<FollowTheLine>().transform.position = player12.GetComponent<FollowTheLine>().waypoints[1].transform.position;
player12.GetComponent<FollowTheLine>().waypointIndex = 1;
player12.GetComponent<FollowTheLine>().waypointIndex += 1;
MovePlayer(12);
}
if (player12StartWaypoint + diceSideThrown == 22)
{
player12.GetComponent<FollowTheLine>().transform.position = player12.GetComponent<FollowTheLine>().waypoints[12].transform.position;
player12.GetComponent<FollowTheLine>().waypointIndex = 12;
player12.GetComponent<FollowTheLine>().waypointIndex += 1;
MovePlayer(12);
}
if (player12StartWaypoint + diceSideThrown == 33)
{
player12.GetComponent<FollowTheLine>().transform.position = player12.GetComponent<FollowTheLine>().waypoints[19].transform.position;
player12.GetComponent<FollowTheLine>().waypointIndex = 19;
player12.GetComponent<FollowTheLine>().waypointIndex += 1;
MovePlayer(12);
}
player12.GetComponent<FollowTheLine>().moveAllowed = false;
player12StartWaypoint = player12.GetComponent<FollowTheLine>().waypointIndex - 1;
}
//Player 10
//if (player10.GetComponent<FollowTheLine>().waypointIndex >
// player10StartWaypoint + diceSideThrown)
//{
// player10.GetComponent<FollowTheLine>().moveAllowed = false;
// player10StartWaypoint = player10.GetComponent<FollowTheLine>().waypointIndex - 1;
//}
//who wins
//if (player1.GetComponent<FollowTheLine>().waypointIndex ==
//player1.GetComponent<FollowTheLine>().waypoints.Length)
//{
// whoWinsTextShadow.gameObject.SetActive(true);
// whoWinsTextShadow.GetComponent<Text>().text = "Player 1 Wins";
// gameOver = true;
// player1MoveText.gameObject.SetActive(true);
// player2MoveText.gameObject.SetActive(false);
// player3MoveText.gameObject.SetActive(false);
// player4MoveText.gameObject.SetActive(false);
// player5MoveText.gameObject.SetActive(false);
// player6MoveText.gameObject.SetActive(false);
// player7MoveText.gameObject.SetActive(false);
// player8MoveText.gameObject.SetActive(false);
// player12MoveText.gameObject.SetActive(false);
//}
//if (player2.GetComponent<FollowTheLine>().waypointIndex ==
//player2.GetComponent<FollowTheLine>().waypoints.Length)
//{
// whoWinsTextShadow.gameObject.SetActive(true);
// whoWinsTextShadow.GetComponent<Text>().text = "Player 2 Wins";
// gameOver = true;
//}
//if (player3.GetComponent<FollowTheLine>().waypointIndex ==
//player3.GetComponent<FollowTheLine>().waypoints.Length)
//{
// whoWinsTextShadow.gameObject.SetActive(true);
// whoWinsTextShadow.GetComponent<Text>().text = "Player 3 Wins";
// gameOver = true;
//}
//if (player4.GetComponent<FollowTheLine>().waypointIndex ==
//player4.GetComponent<FollowTheLine>().waypoints.Length)
//{
// whoWinsTextShadow.gameObject.SetActive(true);
// whoWinsTextShadow.GetComponent<Text>().text = "Player 4 Wins";
// gameOver = true;
//}
//if (player5.GetComponent<FollowTheLine>().waypointIndex ==
//player5.GetComponent<FollowTheLine>().waypoints.Length)
//{
// whoWinsTextShadow.gameObject.SetActive(true);
// whoWinsTextShadow.GetComponent<Text>().text = "Player 5 Wins";
// gameOver = true;
//}
//if (player6.GetComponent<FollowTheLine>().waypointIndex ==
//player6.GetComponent<FollowTheLine>().waypoints.Length)
//{
// whoWinsTextShadow.gameObject.SetActive(true);
// whoWinsTextShadow.GetComponent<Text>().text = "Player 6 Wins";
// gameOver = true;
//}
//if (player7.GetComponent<FollowTheLine>().waypointIndex ==
//player7.GetComponent<FollowTheLine>().waypoints.Length)
//{
// whoWinsTextShadow.gameObject.SetActive(true);
// whoWinsTextShadow.GetComponent<Text>().text = "Player 7 Wins";
// gameOver = true;
//}
//if (player8.GetComponent<FollowTheLine>().waypointIndex ==
//player8.GetComponent<FollowTheLine>().waypoints.Length)
//{
// whoWinsTextShadow.gameObject.SetActive(true);
// whoWinsTextShadow.GetComponent<Text>().text = "Player 8 Wins";
// gameOver = true;
//}
//if (player9.GetComponent<FollowTheLine>().waypointIndex ==
//player9.GetComponent<FollowTheLine>().waypoints.Length)
//{
// whoWinsTextShadow.gameObject.SetActive(true);
// whoWinsTextShadow.GetComponent<Text>().text = "Player 9 Wins";
// gameOver = true;
//}
//if (player10.GetComponent<FollowTheLine>().waypointIndex ==
//player10.GetComponent<FollowTheLine>().waypoints.Length)
//{
// whoWinsTextShadow.gameObject.SetActive(true);
// whoWinsTextShadow.GetComponent<Text>().text = "Player 10 Wins";
// gameOver = true;
//}
if (nofPlayers == 1)
{
player1.SetActive(true);
player2.SetActive(false);
player3.SetActive(false);
player4.SetActive(false);
player5.SetActive(false);
player6.SetActive(false);
player7.SetActive(false);
player8.SetActive(false);
player12.SetActive(false);
}
else if (nofPlayers == 2)
{
player1.SetActive(true);
player2.SetActive(true);
player3.SetActive(false);
player4.SetActive(false);
player5.SetActive(false);
player6.SetActive(false);
player7.SetActive(false);
player8.SetActive(false);
player12.SetActive(false);
}
else if (nofPlayers == 3)
{
player1.SetActive(true);
player2.SetActive(true);
player3.SetActive(true);
player4.SetActive(false);
player5.SetActive(false);
player6.SetActive(false);
player7.SetActive(false);
player8.SetActive(false);
player12.SetActive(false);
}
else if (nofPlayers == 4)
{
player1.SetActive(true);
player2.SetActive(true);
player3.SetActive(true);
player4.SetActive(true);
player5.SetActive(false);
player6.SetActive(false);
player7.SetActive(false);
player8.SetActive(false);
player12.SetActive(false);
}
else if (nofPlayers == 5)
{
player1.SetActive(true);
player2.SetActive(true);
player3.SetActive(true);
player4.SetActive(true);
player5.SetActive(true);
player6.SetActive(false);
player7.SetActive(false);
player8.SetActive(false);
player12.SetActive(false);
}
else if (nofPlayers == 6)
{
player1.SetActive(true);
player2.SetActive(true);
player3.SetActive(true);
player4.SetActive(true);
player5.SetActive(true);
player6.SetActive(true);
player7.SetActive(false);
player8.SetActive(false);
player12.SetActive(false);
}
else if (nofPlayers == 7)
{
player1.SetActive(true);
player2.SetActive(true);
player3.SetActive(true);
player4.SetActive(true);
player5.SetActive(true);
player6.SetActive(true);
player7.SetActive(true);
player8.SetActive(false);
player12.SetActive(false);
}
else if (nofPlayers == 8)
{
player1.SetActive(true);
player2.SetActive(true);
player3.SetActive(true);
player4.SetActive(true);
player5.SetActive(true);
player6.SetActive(true);
player7.SetActive(true);
player8.SetActive(true);
player12.SetActive(false);
}
else if (nofPlayers == 9)
{
player1.SetActive(true);
player2.SetActive(true);
player3.SetActive(true);
player4.SetActive(true);
player5.SetActive(true);
player6.SetActive(true);
player7.SetActive(true);
player8.SetActive(true);
player12.SetActive(true);
}
}
public static void MovePlayer(int playerToMove)
{
switch (playerToMove)
{
case 1:
player1.GetComponent<FollowTheLine>().moveAllowed = true;
break;
case 2:
player2.GetComponent<FollowTheLine>().moveAllowed = true;
break;
case 3:
player3.GetComponent<FollowTheLine>().moveAllowed = true;
break;
case 4:
player4.GetComponent<FollowTheLine>().moveAllowed = true;
break;
case 5:
player5.GetComponent<FollowTheLine>().moveAllowed = true;
break;
case 6:
player6.GetComponent<FollowTheLine>().moveAllowed = true;
break;
case 7:
player7.GetComponent<FollowTheLine>().moveAllowed = true;
break;
case 8:
player8.GetComponent<FollowTheLine>().moveAllowed = true;
break;
case 9:
player12.GetComponent<FollowTheLine>().moveAllowed = true;
break;
}
}
}
And the Error is:
NullReferenceException: Object reference not set to an instance of an object
at LadderControl.Start () [0x00177] in D:\Users\daniel_diezel\entwicklung\test\party_games\Assets\Scripts\MultiplayerLadder\LadderControl.cs:89
(Filename: D:/Users/daniel_diezel/entwicklung/test/party_games/Assets/Scripts/MultiplayerLadder/LadderControl.cs Line: 81)
NullReferenceException: Object reference not set to an instance of an object
at LadderControl.Update () [0x00998] in D:\Users\daniel_diezel\entwicklung\test\party_games\Assets\Scripts\MultiplayerLadder\LadderControl.cs:291
(Filename: D:/Users/daniel_diezel/entwicklung/test/party_games/Assets/Scripts/MultiplayerLadder/LadderControl.cs Line: 291)

