Skip to content

Instantly share code, notes, and snippets.

@prophetgoddess
Created June 1, 2013 22:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save prophetgoddess/5691922 to your computer and use it in GitHub Desktop.
Save prophetgoddess/5691922 to your computer and use it in GitHub Desktop.
Source for Pong
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();
}
}
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");
}
}
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();
}
}
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