Advertisement
Guest User

Untitled

a guest
Dec 18th, 2014
152
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.50 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4. public class ClickToMove : MonoBehaviour {
  5.  
  6. public float speed = 1.5f;
  7. private Vector3 TargetPosition;
  8.  
  9. void Start () {
  10. TargetPosition = transform.position;
  11. }
  12.  
  13. void Update () {
  14. if (Input.GetMouseButtonDown(0)) {
  15. TargetPosition = Camera.main.ScreenToWorldPoint(Input.mousePosition);
  16. TargetPosition.z = transform.position.z;
  17. }
  18. transform.position = Vector2.MoveTowards(transform.position, TargetPosition, speed * Time.deltaTime);
  19. }
  20. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement