Created
June 1, 2013 22:23
-
-
Save prophetgoddess/5691922 to your computer and use it in GitHub Desktop.
Source for Pong
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
using System.Collections; | |
public class enemyScore : MonoBehaviour { | |
public static int scoreEnemy = 0; | |
void OnCollisionEnter(Collision collision ){ | |
playerscore.scorePlayer = playerscore.scorePlayer + 1; | |
keepScore.reset(); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
using System.Collections; | |
public class keepScore : MonoBehaviour { | |
void Start(){ | |
DontDestroyOnLoad(transform.gameObject); | |
} | |
void Update(){ | |
if(playerscore.scorePlayer == 9){ | |
victory("player"); | |
} | |
else if(enemyScore.scoreEnemy == 9){ | |
victory("enemy"); | |
} | |
} | |
public void victory(string winner){ | |
if(winner == "player"){ | |
Debug.Log("Player Wins"); | |
Application.LoadLevel("PlayerVictory"); | |
} | |
else if(winner == "enemy"){ | |
Debug.Log("Enemy Wins"); | |
Application.LoadLevel("EnemyVictory"); | |
} | |
} | |
public static void reset(){ | |
Application.LoadLevel("pong"); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
using System.Collections; | |
public class playerscore : MonoBehaviour { | |
public static int scorePlayer = 0; | |
void OnCollisionEnter(Collision collision){ | |
enemyScore.scoreEnemy = enemyScore.scoreEnemy + 1; | |
keepScore.reset(); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
using System.Collections; | |
public class scoreGui : MonoBehaviour { | |
void Start(){ | |
DontDestroyOnLoad(transform.gameObject); | |
} | |
// Update is called once per frame | |
void OnGUI() { | |
GUI.Label(new Rect(10, 10, 100, 20), playerscore.scorePlayer + " vs " + enemyScore.scoreEnemy); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment