daily pastebin goal
41%
SHARE
TWEET

Untitled

a guest Jan 29th, 2018 63 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using UnityEngine;
  2.  
  3. public class Movement : MonoBehaviour {
  4.  
  5.     public float speed;
  6.     public Vector2 curPosition;
  7.  
  8.     Camera cam;
  9.  
  10.     private void Start()
  11.     {
  12.         cam = Camera.main;
  13.         curPosition.x = transform.position.x;
  14.         curPosition.y = transform.position.y;
  15.     }
  16.  
  17.     private void Update()
  18.     {
  19.         RaycastHit2D _hit = Physics2D.Raycast(Camera.main.ScreenToWorldPoint(Input.mousePosition), Vector2.zero);
  20.  
  21.         if (Input.GetMouseButtonDown(0) && _hit.collider != null)
  22.         {
  23.             Debug.Log("Target Position: " + _hit.collider.gameObject.transform.position);
  24.             transform.position = Vector2.MoveTowards(curPosition, _hit.point, Time.deltaTime * speed);
  25.         }
  26.     }
  27. }
RAW Paste Data
Pastebin PRO WINTER Special!
Get 40% OFF Pastebin PRO accounts!
Top