SHARE
TWEET

Untitled

a guest Sep 6th, 2012 43 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4. public class RadialDragger : MonoBehaviour {
  5.        
  6.         public GameObject Dragger;
  7.         public Transform Planet;
  8.         public float Distance;
  9.  
  10.         // Use this for initialization
  11.         void Start () {
  12.        
  13.         }
  14.        
  15.         // Update is called once per frame
  16.         void Update () {
  17.                
  18.                 Vector2 MouseInputPos = Input.mousePosition;
  19.                
  20.                 Ray NewRay = Camera.main.ScreenPointToRay(MouseInputPos);
  21.                 RaycastHit NewHit = new RaycastHit();
  22.                 Planet.transform.collider.Raycast(NewRay,out NewHit,100.0f);
  23.                
  24.                 Vector3 Direction = Planet.transform.position - GetWorldPos(MouseInputPos);
  25.                 Debug.DrawRay(Dragger.transform.position, Direction);
  26.                 Vector3 targetPosition = GetWorldPos(MouseInputPos) - Planet.position;
  27.                 float Ratio = Distance / targetPosition.magnitude;
  28.                 targetPosition.Scale( new Vector3(Ratio, Ratio, Ratio));
  29.                 Dragger.transform.position = targetPosition + Planet.position;
  30.                
  31.                
  32.         }
  33.        
  34.        
  35.        
  36.             Vector3 GetWorldPos( Vector2 screenPos )
  37.     {
  38.         Camera mainCamera = Camera.main;
  39.         return mainCamera.ScreenToWorldPoint(new Vector3(screenPos.x, screenPos.y, Mathf.Abs(Planet.position.z - mainCamera.transform.position.z)));
  40.  
  41.     }
  42.        
  43. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top