Advertisement
Guest User

Untitled

a guest
Nov 26th, 2016
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.11 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4. public class MouseMove2D : MonoBehaviour {
  5.  
  6.     public Vector3 mousePosition;
  7.     public float moveSpeed = 0.1f;
  8.     public Camera Cam;
  9.  
  10.     public LayerMask layers;
  11.     public Transform Raystart;
  12.     [SerializeField] private bool m_ShowDebugRay;                   // Optionally show the debug ray.
  13.     [SerializeField] private float m_DebugRayLength = 5f;           // Debug ray length.
  14.     [SerializeField] private float m_DebugRayDuration = 1f;         // How long the Debug ray will remain visible.
  15.     [SerializeField] private float m_RayLength = 500f;              // How far into the scene the ray is cast.
  16.  
  17.     // Use this for initialization
  18.     void Start () {
  19.         Cam = Camera.main;
  20.     }
  21.  
  22.     // Update is called once per frame
  23.     void Update () {
  24.         //if ( Input.GetMouseButton (1)){ // << use GetMouseButton instead of GetMouseButtonDown
  25.             RaycastHit hit;
  26.             Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
  27.             if ( Physics.Raycast (ray,out hit,100.0f)) {
  28. //              Debug.Log("You selected the " + hit.transform.name);
  29.                 mousePosition = hit.point;
  30.                 transform.position = hit.point;
  31.                 //hit.transform.position += Vector3.right * moveSpeed * Time.deltaTime; // << declare public speed and set it in inspector
  32.             }
  33.         //}
  34.  
  35.         //mousePosition = Input.mousePosition;
  36.         //mousePosition = Camera.main.ScreenToWorldPoint(mousePosition);
  37.  
  38.         if (m_ShowDebugRay)
  39.         {
  40.             //Debug.DrawRay(Raystart.transform.position, mousePosition * m_DebugRayLength, Color.yellow, m_DebugRayDuration);
  41.  
  42.         /*
  43.         Ray ray = new Ray (transform.position, transform.forward);
  44.  
  45.         // Raycast to find a ragdoll collider
  46.         RaycastHit hit = new RaycastHit();
  47.         if (Physics.Raycast(ray, out hit, 100f, layers)) {
  48.             Debug.DrawRay(transform.position, transform.forward * m_DebugRayLength, Color.red, m_DebugRayDuration);
  49.         }
  50.         */
  51.         }
  52.  
  53.  
  54.         if (Input.GetMouseButton(0)) {
  55.             //mousePosition = Input.mousePosition;
  56.             //mousePosition = Camera.main.ScreenToWorldPoint(mousePosition);
  57.             //transform.position = mousePosition;
  58.             //transform.position = Vector3.Lerp(transform.position, mousePosition, moveSpeed);
  59.         }
  60.  
  61.     }
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement