Advertisement
MonoFinity

Untitled

May 23rd, 2017
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.29 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class Ball : MonoBehaviour {
  6.    
  7.  
  8.     public ControllerGrabObject connectedController;//(not used for anything yet, but might become useful)  use:  if(connectedController) //returns true if this ball is connected to a controller
  9.  
  10.     Rigidbody rb;
  11.  
  12.  
  13.  
  14.     private void Start() {
  15.         rb=GetComponent<Rigidbody>();
  16.     }
  17.  
  18.  
  19.  
  20.     void OnTriggerEnter(Collider otherCol)
  21.     {
  22.         //if(is "GRAB" button is pressed? ){//TODO!
  23.  
  24.        ControllerGrabObject grabObj=otherCol.transform.root.GetComponent<ControllerGrabObject>();
  25.  
  26.         if(grabObj){//does this collider have a ControllerGrabObject component?  if so, assign it!
  27.             connectedController=grabObj;
  28.             transform.parent=connectedController.transform;//become a child of this controller!
  29.             rb.isKinematic=true; // while held by controller, do NOT run physics (setting true means we will control its kinetic motion MANUALLY via its transform
  30.         }
  31.  
  32.         //}
  33.     }
  34.  
  35.  
  36.    public  void throwFromController(Vector3 throwForce) //call this function when player pressed THROW button!
  37.     {
  38.         connectedController=null;
  39.         transform.parent=null;// return to world space
  40.  
  41.         rb.isKinematic=false;//Activate Unity Physics again!
  42.         rb.velocity=throwForce;//THROW!
  43.  
  44.     }
  45.  
  46.    
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement