Hello, i use a click to move script, when i press to play form unity everything works but when i build game then i press click but character dont moves
(mouse click work bcause i checked other actions and works, just character dont moves)
this is my script (still not completed) (Fixed)
WARNING: Add “Ground” tag in your world-terrain or edit script
using UnityEngine;
using System.Collections;
public class C2Move : MonoBehaviour
{
// The Camera we use
public Camera myCamera;
// Target Point
private Vector3 TPoint;
public float Speed = 5.0f;
private float MaxClickDist = 1000.0f;
public float Distance
{
get;
set;
}
void Start ()
{
// Initial Points
TPoint = transform.position;
}
void Update ()
{
HandleClick();
}
void HandleClick()
{
if (Input.GetMouseButtonDown(0))
{
// Get Clicked Position in 3D World
Ray ray = myCamera.ScreenPointToRay(Input.mousePosition);
RaycastHit hit;
if (Physics.Raycast(ray, out hit, MaxClickDist))
{
// This will allow take target without any prob
if (hit.transform.tag != "Ground")
return;
TPoint = hit.point;
}
}
// Move character
MoveCharacter();
}
void MoveCharacter()
{
Distance = Vector3.Distance(TPoint, transform.position);
if (Distance > 0.2f)
{
LookAtPoint();
transform.position = Vector3.MoveTowards(transform.position, TPoint, Time.deltaTime * Speed);
}
}
void LookAtPoint ()
{
Distance = Vector3.Distance(TPoint, transform.position);
if (Distance > 1.0f)
{
Quaternion targetRotation = Quaternion.LookRotation(TPoint - transform.position);
transform.rotation = targetRotation;
}
}
}