Advertisement
dantepw

Untitled

Jul 3rd, 2015
243
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.59 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4. public class Ball : MonoBehaviour {
  5.  
  6.     public Paddle paddle;
  7.     public Rigidbody2D rigidbody2D;
  8.    
  9.     private Vector3 paddleToBallVector;
  10.  
  11.     void Start ()
  12.     {
  13.         paddleToBallVector = this.transform.position - paddle.transform.position;  
  14.         print ("paddleToBall: "+paddleToBallVector);
  15.     }
  16.    
  17.     void Update () {
  18.         this.transform.position = paddle.transform.position + paddleToBallVector;
  19.        
  20.         if (Input.GetMouseButtonDown(0))
  21.         {
  22.             print ("Mouse clicked, launching ball!");
  23.            
  24.             this.rigidbody2D.velocity = new Vector2 (10f, 10f);
  25.         }
  26.     }
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement