Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class Ball : MonoBehaviour {
- 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
- Rigidbody rb;
- private void Start() {
- rb=GetComponent<Rigidbody>();
- }
- void OnTriggerEnter(Collider otherCol)
- {
- //if(is "GRAB" button is pressed? ){//TODO!
- ControllerGrabObject grabObj=otherCol.transform.root.GetComponent<ControllerGrabObject>();
- if(grabObj){//does this collider have a ControllerGrabObject component? if so, assign it!
- connectedController=grabObj;
- transform.parent=connectedController.transform;//become a child of this controller!
- rb.isKinematic=true; // while held by controller, do NOT run physics (setting true means we will control its kinetic motion MANUALLY via its transform
- }
- //}
- }
- public void throwFromController(Vector3 throwForce) //call this function when player pressed THROW button!
- {
- connectedController=null;
- transform.parent=null;// return to world space
- rb.isKinematic=false;//Activate Unity Physics again!
- rb.velocity=throwForce;//THROW!
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement