Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- public class ArcanoidBall : MonoBehaviour
- {
- //ball speed
- public float speed = 5f;
- //function which adds speed to the ball
- public void RunBall()
- {
- //Randomizing direction
- float x = Random.Range(0, 2) == 0 ? -1 : 1;
- GetComponent<Rigidbody>().velocity = new Vector3(x * speed, speed, 0f);
- }
- //Stopping movement
- public void StopBall()
- {
- GetComponent<Rigidbody>().velocity = new Vector3(0, 0, 0);
- }
- private void Start()
- {
- //Starting the ball when the game start. Can be removed later
- //RunBall();
- }
- //Checking if the ball collided with Lose cube
- private void OnCollisionEnter(Collision collision)
- {
- if(collision.gameObject.name == "Lose")
- {
- GameManager.instance.EndGame(false);
- Debug.Log("Game Over");
- this.gameObject.GetComponent<Renderer>().enabled = false;
- }
- }
- }
Add Comment
Please, Sign In to add comment