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.UIElements;
- public class Ball : MonoBehaviour
- {
- //Prędkość piłki
- public float speed = 5f;
- public void StartGame()
- {
- //losowanie kierunku, w który poleci piłka
- float x = Random.Range(0, 2) == 0 ? -1 : 1;
- float y = Random.Range(0, 2) == 0 ? -1 : 1;
- GetComponent<Rigidbody>().velocity = new Vector3(x * speed, y * speed, 0f);
- }
- //Ustawienie pozycji startowej
- public void SetStartPosition()
- {
- //położenie na środku sceny
- transform.position = new Vector3(0, 0, 0);
- //zatrzymanie prędkości
- GetComponent<Rigidbody>().velocity = new Vector3(0, 0, 0);
- }
- private void OnCollisionEnter(Collision collision)
- {
- if(collision.gameObject.name == "Player2Area")
- {
- PongManager.instance.UpdatePoints(true);
- PongManager.instance.gameRun = false;
- SetStartPosition();
- }
- if (collision.gameObject.name == "Player1Area")
- {
- PongManager.instance.UpdatePoints(false);
- PongManager.instance.gameRun = false;
- SetStartPosition();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement