using UnityEngine;
using System. Collections;
public class PropertiesAndCoroutines : MonoBehaviour
{
public float smoothing = 7f ;
public Vector3 Target
{
get { return target; }
set
{
target = value ;
StopCoroutine ( "Movement" ) ;
StartCoroutine ( "Movement" , target) ;
}
}
private Vector3 target;
IEnumerator Movement ( Vector3 target)
{
while ( Vector3. Distance ( transform. position, target) > 0.05f )
{
transform. position = Vector3. Lerp ( transform. position, target, smoothing * Time. deltaTime) ;
yield return null ;
}
}
}
using UnityEngine;
using System. Collections;
public class ClickSetPosition : MonoBehaviour
{
public PropertiesAndCoroutines coroutineScript;
void OnMouseDown ( )
{
Ray ray = Camera. main. ScreenPointToRay ( Input. mousePosition) ;
RaycastHit hit;
Physics. Raycast ( ray, out hit) ;
if ( hit. collider. gameObject == gameObject)
{
Vector3 newTarget = hit. point;
coroutineScript. Target = newTarget;
}
}
}