Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class RaycastCube : MonoBehaviour {
  6.     Ray myRay;
  7.     RaycastHit myRaycasthit;
  8.     public GameObject target;
  9.     public bool isDebug = true, isMoving = false;
  10.     // Use this for initialization
  11.     // void Start () {
  12.        
  13.     // }
  14.    
  15.     // Update is called once per frame
  16.     void Update () {
  17.         if(Input.GetMouseButtonUp(1)){
  18.             myRay = Camera.main.ScreenPointToRay(Input.mousePosition);
  19.             Physics.Raycast(myRay, out myRaycasthit, 300);
  20.             target.transform.position = myRaycasthit.point + new Vector3(0, 0.1f , 0);
  21.             transform.LookAt(target.transform);
  22.         }
  23.         if(isMoving && Vector3.Distance(transform.position, target.transform.position) > 0.6f){
  24.             transform.position = Vector3.MoveTowards
  25.             (transform.position, target.transform.position, 10*Time.deltaTime);
  26.         }
  27.         if(isDebug){
  28.             Debug.DrawLine(GameObject.Find("Main Camera")
  29.                 .gameObject.transform.position, myRaycasthit.point, Color.red);
  30.         }
  31.     }
  32. }