Advertisement
Guest User

ScoreboardUpdater.cs

a guest
Dec 29th, 2013
2,743
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.29 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4. public class ScoreboardUpdater : MonoBehaviour {
  5.     //as in the enemyAI, once we link this variable, we'll be able to reference and control the ball from this script
  6.     public GameObject ball;
  7.     private float myscore;
  8.     private float enemyscore;
  9.    
  10.     // Use this for initialization
  11.     void Start () {
  12.         //this declares two score variables that we'll use to store the points scored by both sides
  13.         myscore = 0;
  14.         enemyscore = 0;
  15.     }
  16.    
  17.     // Update is called once per frame
  18.     void Update () {
  19.        
  20.         //this generates a new 'score' string given the states of both variables
  21.         GetComponent<TextMesh>().text = enemyscore.ToString() + " || " + myscore.ToString();
  22.         //this checks if the ball is out of bounds, increments the appropriate score,
  23.         //and resets the ball's position and velocity
  24.         if (ball.transform.position.x > 14){
  25.             myscore++;
  26.             ball.transform.position = new Vector3(7,0,2);
  27.             ball.rigidbody.velocity = new Vector3(0,0,0);
  28.             ball.rigidbody.AddForce(Vector3.right * 200 + Vector3.forward * 100);
  29.         }
  30.         if (ball.transform.position.x < -2){
  31.             enemyscore++;
  32.             ball.transform.position = new Vector3(7,0,2);
  33.             ball.rigidbody.velocity = new Vector3(0,0,0);
  34.             ball.rigidbody.AddForce(Vector3.right * 200 + Vector3.forward * 100);
  35.         }
  36.        
  37.     }
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement