using UnityEngine;
using System.Collections;
public class Movement : MonoBehaviour
{
private Vector3 targetPosition1;
public int speed = 60;
Plane playerPlane;
Ray ray;
float hitdist;
// Use this for initialization
void Start ()
{
}
// Update is called once per frame
void Update ()
{
if (Input.GetMouseButtonDown(1))
{
playerPlane = new Plane(Vector3.up, transform.position);
ray = Camera.main.ScreenPointToRay(Input.mousePosition);
hitdist = 0.0f;
if (playerPlane.Raycast(ray, hitdist))
{
Vector3 targetPoint = ray.GetPoint(hitdist);
Vector3 targetPosition = ray.GetPoint(hitdist);
Quaternion targetRotation = Quaternion.LookRotation(targetPoint - transform.position);
transform.rotation = targetRotation;
}
Vector3 dir = targetPosition1 - transform.position;
float dist = dir.magnitude;
float move = speed * Time.deltaTime;
if(dist > move)
{
transform.position += dir.normalized * move;
}
else
{
transform.position = targetPosition1;
}
transform.position += (targetPosition1 - transform.position).normalized * speed * Time.deltaTime;
}
}