Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class BallScript : MonoBehaviour
- {
- public Rigidbody2D rb;
- public bool InPlay;
- public Transform Paddle;
- public float speed;
- public Transform exploision;
- public GameManager GM;
- // Start is called before the first frame update
- void Start()
- {
- rb = GetComponent<Rigidbody2D>();
- }
- // Update is called once per frame
- void Update()
- {
- if (!InPlay){
- transform.position = Paddle.position;
- }
- if (Input.GetButtonDown("Jump") && !InPlay)
- {
- InPlay = true;
- rb.AddForce(Vector2.up * speed);
- }
- }
- void OnTriggerEnter2D(Collider2D other)
- {
- if (other.CompareTag("Bottom"))
- {
- Debug.Log("Out!");
- rb.velocity = Vector2.zero;
- InPlay = false;
- GM.UpdateLives(-1);
- }
- }
- private void OnCollisionEnter2D(Collision2D other)
- {
- if (other.transform.CompareTag("Brick"))
- {
- Transform newExplosion = Instantiate(exploision, other.transform.position, other.transform.rotation);
- Destroy(newExplosion.gameObject, 2.5f);
- GM.UpdateScore (other.gameObject.GetComponent<BrickScript>().points);
- Destroy (other.gameObject);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement