SHARE
TWEET
Untitled
a guest
Jan 29th, 2018
63
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
- using UnityEngine;
- public class Movement : MonoBehaviour {
- public float speed;
- public Vector2 curPosition;
- Camera cam;
- private void Start()
- {
- cam = Camera.main;
- curPosition.x = transform.position.x;
- curPosition.y = transform.position.y;
- }
- private void Update()
- {
- RaycastHit2D _hit = Physics2D.Raycast(Camera.main.ScreenToWorldPoint(Input.mousePosition), Vector2.zero);
- if (Input.GetMouseButtonDown(0) && _hit.collider != null)
- {
- Debug.Log("Target Position: " + _hit.collider.gameObject.transform.position);
- transform.position = Vector2.MoveTowards(curPosition, _hit.point, Time.deltaTime * speed);
- }
- }
- }
RAW Paste Data

