Skip to content

Instantly share code, notes, and snippets.

@mm-uddin
Created April 7, 2016 04:05
Show Gist options
  • Save mm-uddin/204c13efcc6409a0a424f38b0672cb74 to your computer and use it in GitHub Desktop.
Save mm-uddin/204c13efcc6409a0a424f38b0672cb74 to your computer and use it in GitHub Desktop.
using UnityEngine;
using System.Collections;
public class Score : MonoBehaviour {
public TextMesh currentScore;
public GameObject ballPref;
public Transform paddleObj;
GameObject ball;
int score;
void Update () {
ball = GameObject.FindGameObjectWithTag ("Ball");
currentScore.text = " " + score;
}
void OnTriggerEnter (Collider other){
if (other.tag=="Ball") {
score += 1;
Destroy (ball);
(Instantiate (ballPref, new Vector3 (paddleObj.transform.position.x + 2, paddleObj.transform.position.y, 0), Quaternion.identity) as GameObject).transform.parent = paddleObj;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment