using UnityEngine; using System.Collections; public class PlayerScript : MonoBehaviour { public Camera playerCamera; private bool reachedGoal; public GameObject bulletPrefab; public float shotCooldown; private float lastShotTime; public Font font; private bool tryingToEnterGoal = false; public int[] requiresBall; // Use this for initialization void Start () { lastShotTime = 0.0f; } // Update is called once per frame void Update () { /*if ( Input.GetButton( "Fire1" ) ) { if ( Time.fixedTime >= lastShotTime + shotCooldown ) { lastShotTime = Time.fixedTime; //for ( int i = 0; i < 8; i++ ) { Instantiate( bulletPrefab, this.gameObject.transform.position, this.gameObject.transform.rotation ); //} } }*/ } void OnGUI() { GUIStyle boxStyle = GUI.skin.GetStyle( "Box" ); boxStyle.alignment = TextAnchor.MiddleCenter; boxStyle.fontSize = 20; boxStyle.font = font; GUI.backgroundColor = new Color( 0.0f, 0.0f, 0.0f, 1.0f ); if ( reachedGoal ) { GlobalVariables globalVariables = GameObject.Find( "Overseer" ).GetComponent( "GlobalVariables" ) as GlobalVariables; if ( globalVariables.numberOfPlayersInGoal != globalVariables.numberOfPlayers ) { GUI.Box( new Rect( playerCamera.camera.pixelRect.x, playerCamera.camera.pixelRect.y, playerCamera.camera.pixelRect.width, playerCamera.camera.pixelRect.height ), "This world is saved", boxStyle ); } } else { if ( tryingToEnterGoal ) { GUI.Box( new Rect( playerCamera.camera.pixelRect.x, playerCamera.camera.pixelRect.y, playerCamera.camera.pixelRect.width, playerCamera.camera.pixelRect.height ), "More souls need saving", boxStyle ); } } } void OnTriggerEnter2D( Collider2D collider ) { if ( collider.gameObject.CompareTag( "PlayerGoal" ) ) { tryingToEnterGoal = true; } } void OnTriggerExit2D( Collider2D collider ) { if ( collider.gameObject.CompareTag( "PlayerGoal" ) ) { tryingToEnterGoal = false; } } public void ReachedGoal() { GlobalVariables globalVariables = GameObject.Find( "Overseer" ).GetComponent( "GlobalVariables" ) as GlobalVariables; bool requiredBallsInGoal = true; foreach ( int ballId in requiresBall ) { if ( !globalVariables.ballInGoal[ ballId - 1 ] ) { requiredBallsInGoal = false; } } if ( requiredBallsInGoal ) { // Reached goal if ( !this.reachedGoal ) { this.reachedGoal = true; //playerCamera.enabled = false; globalVariables.playerReachedGoal(); this.gameObject.collider2D.enabled = false; } else { this.reachedGoal = false; //playerCamera.enabled = false; globalVariables.playerUnReachedGoal(); this.gameObject.collider2D.enabled = true; } } } }