Advertisement
Guest User

Untitled

a guest
Jun 23rd, 2017
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.78 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.UI;
  5.  
  6. public class Score : MonoBehaviour {
  7. public Text Text;
  8. public GameObject Ball;
  9. public Transform Paddle;
  10. public float BallMount;
  11. private GameObject BallReference;
  12. private int CurrentScore;
  13.  
  14. void Update() {
  15. if(BallReference == null)
  16. BallReference = GameObject.FindObjectOfType<Ball>().gameObject;
  17.  
  18. Text.text = CurrentScore.ToString();
  19. }
  20.  
  21. void OnTriggerenter2D(Collider2D other) {
  22. if(other.gameObject.name.Contains("Ball")) {
  23. CurrentScore += 1;
  24. Destroy(BallReference);
  25. (Instantiate(Ball, new Vector3(Paddle.transform.position.x + BallMount, Paddle.transform.position.y, 0), Quaternion.identity) as GameObject).transform.parent = Paddle;
  26. }
  27. }
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement