Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Collections;
- public class ScoreboardUpdater : MonoBehaviour {
- //as in the enemyAI, once we link this variable, we'll be able to reference and control the ball from this script
- public GameObject ball;
- private float myscore;
- private float enemyscore;
- // Use this for initialization
- void Start () {
- //this declares two score variables that we'll use to store the points scored by both sides
- myscore = 0;
- enemyscore = 0;
- }
- // Update is called once per frame
- void Update () {
- //this generates a new 'score' string given the states of both variables
- GetComponent<TextMesh>().text = enemyscore.ToString() + " || " + myscore.ToString();
- //this checks if the ball is out of bounds, increments the appropriate score,
- //and resets the ball's position and velocity
- if (ball.transform.position.x > 14){
- myscore++;
- ball.transform.position = new Vector3(7,0,2);
- ball.rigidbody.velocity = new Vector3(0,0,0);
- ball.rigidbody.AddForce(Vector3.right * 200 + Vector3.forward * 100);
- }
- if (ball.transform.position.x < -2){
- enemyscore++;
- ball.transform.position = new Vector3(7,0,2);
- ball.rigidbody.velocity = new Vector3(0,0,0);
- ball.rigidbody.AddForce(Vector3.right * 200 + Vector3.forward * 100);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement