Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Collections;
- public class Ball1 : MonoBehaviour {
- private Paddle paddle;
- private bool hasStarted;
- private Vector3 paddleToBallVector;
- private Vector2 launch;
- // Use this for initialization
- void Start () {
- paddle = GameObject.FindObjectOfType<Paddle> ();
- paddleToBallVector = this.transform.position - paddle.transform.position;
- }
- // Update is called once per frame
- void Update () {
- //print (Input.mousePosition / Screen.width * 16);
- if (!hasStarted) {
- this.transform.position = paddle.transform.position + paddleToBallVector;
- }
- if (Input.GetMouseButtonDown (1)) {
- hasStarted = true;
- launch = new Vector2 (Random.Range(-5f , 5f), 10f);
- this.GetComponent<Rigidbody2D> ().velocity = launch;
- }
- }
- void OnCollisionEnter2D (Collision2D col){
- print ("Velocity = " + launch );
- Vector2 fly = new Vector2 (Random.Range (0f, 1f), 10f);
- Debug.Log (Time.time.ToString () + ": New Vector 2 fly :" + fly);
- GetComponent<Rigidbody2D>().velocity += fly;
- Debug.Log (Time.time.ToString() + ": Ball velocity: " + GetComponent<Rigidbody2D>().velocity);
- if (hasStarted) {
- GetComponent<AudioSource> ().Play ();
- GetComponent<Rigidbody2D> ().velocity += fly;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment