Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.UI;
- public class Score : MonoBehaviour {
- public Text Text;
- public GameObject Ball;
- public Transform Paddle;
- public float BallMount;
- private GameObject BallReference;
- private int CurrentScore;
- void Update() {
- if(BallReference == null)
- BallReference = GameObject.FindObjectOfType<Ball>().gameObject;
- Text.text = CurrentScore.ToString();
- }
- void OnTriggerenter2D(Collider2D other) {
- if(other.gameObject.name.Contains("Ball")) {
- CurrentScore += 1;
- Destroy(BallReference);
- (Instantiate(Ball, new Vector3(Paddle.transform.position.x + BallMount, Paddle.transform.position.y, 0), Quaternion.identity) as GameObject).transform.parent = Paddle;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement