Advertisement
Guest User

Untitled

a guest
Oct 22nd, 2019
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.42 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class BallScript : MonoBehaviour
  6. {
  7.     public Rigidbody2D rb;
  8.     public bool InPlay;
  9.     public Transform Paddle;
  10.     public float speed;
  11.     public Transform exploision;
  12.     public GameManager GM;
  13.  
  14.     // Start is called before the first frame update
  15.     void Start()
  16.     {
  17.         rb = GetComponent<Rigidbody2D>();
  18.  
  19.        
  20.     }
  21.  
  22.     // Update is called once per frame
  23.     void Update()
  24.     {
  25.         if (!InPlay){
  26.             transform.position = Paddle.position;
  27.         }
  28.  
  29.         if (Input.GetButtonDown("Jump") && !InPlay)
  30.         {
  31.             InPlay = true;
  32.             rb.AddForce(Vector2.up * speed);
  33.         }
  34.     }
  35.  
  36.     void OnTriggerEnter2D(Collider2D other)
  37.     {
  38.         if (other.CompareTag("Bottom"))
  39.         {
  40.             Debug.Log("Out!");
  41.             rb.velocity = Vector2.zero;
  42.             InPlay = false;
  43.             GM.UpdateLives(-1);
  44.         }
  45.     }
  46.  
  47.     private void OnCollisionEnter2D(Collision2D other)
  48.     {
  49.         if (other.transform.CompareTag("Brick"))
  50.         {
  51.            Transform newExplosion = Instantiate(exploision, other.transform.position, other.transform.rotation);
  52.             Destroy(newExplosion.gameObject, 2.5f);
  53.  
  54.             GM.UpdateScore (other.gameObject.GetComponent<BrickScript>().points);
  55.  
  56.             Destroy (other.gameObject);
  57.         }
  58.     }
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement