333GameStudio

DragAround

Feb 2nd, 2017
285
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #pragma strict
  2.  
  3. var object2 : GameObject;
  4. var clicked = false;
  5.  
  6. function Update () {
  7.  var up = transform.TransformDirection(Vector3.forward);
  8.    var hit : RaycastHit;    
  9.    Debug.DrawRay(transform.position, up * 5, Color.red);
  10.        
  11.        if(Physics.Raycast(transform.position, up, hit, 5)){
  12.       if(hit.collider.gameObject.tag == "Cube"){
  13.  
  14.     if(Input.GetMouseButton(0)){
  15.        
  16.            
  17.                
  18.      
  19.      
  20.         (hit.collider.gameObject).transform.parent = object2.transform ;
  21.        
  22.        (hit.collider.GetComponent.<Rigidbody>()).isKinematic = true;
  23.        
  24. }else{
  25.  
  26. (hit.collider.gameObject).transform.parent = null;
  27. (hit.collider.GetComponent.<Rigidbody>()).isKinematic = false;
  28. }
  29. }
  30. }
  31. }
Advertisement
Add Comment
Please, Sign In to add comment