Essentially my friend and I have two scripts, and two player controllers. Both controllers move at the same time but you need to get them to two goals at the same time to advance to the next level. We keep getting a collision based error, any ideas? Here are the scripts:
using UnityEngine;
using System.Collections;
public class PlayerNewScene1 : MonoBehaviour {
public bool isPlayer1 = false;
void OnTriggerEnter2D(Collider2D other)
{
//if (other.gameObject.tag == "Player")
if (other.gameObject.tag == "Player1")
{
isPlayer1 = true;
}else{
isPlayer1 = false;
}
}
}
2:
using UnityEngine;
using System.Collections;
public class PlayerNewScene2 : MonoBehaviour {
public bool isPlayer2 = false;
//public bool whatisValue;
//GameObject thePlayer = GameObject.Find ("ThePlayer");
//PlayerNewScene1 playerScript = thePlayer.GetComponent<PlayerNewScene1>();
void OnTriggerEnter2D(Collider2D other)
{
GameObject thePlayer = GameObject.Find ("Basic Player Controller");
PlayerNewScene1 playerScript = thePlayer.GetComponent<PlayerNewScene1>();
//var attribute1 = GetComponent<PlayerNewScene1>();
//whatisValue = attribute1.isPlayer1;
//if (other.gameObject.tag == "Player")
//var attribute1 = GetComponent<PlayerNewScene1>();
//PlayerNewScene1 as1 = GetComponent<PlayerNewScene1>();
if (other.gameObject.tag == "Player2")
{
isPlayer2 = true;
}else{
isPlayer2 = false;
}
if (isPlayer2) {
if (playerScript.isPlayer1){
Application.LoadLevel ("level2");
isPlayer2 = false;
}
}
//Application.LoadLevel ("level2");
}
}