Hello, I am having a issue on creating a “target” icon in third person view, on where the mouse is clicked, and having it relocate when I click another position, when I click, or when the player uses keyboard/controller movement it vanishes.
The ISSUE is I’ve tried using Instantiate(), however that creates multiple objects. And I’ve tried using Destroy() and DestroyImmediate(), but when I click again Unity says the Object is well destroyed.
Thank You in advance, and if this is a duplicate question, let me know and give a working link. Everything I’ve searched for has brought up the Instantiate(), Destory() items.
This is my current code:
if ( (Input.GetMouseButtonDown(0) && GUIUtility.hotControl ==0) ||
(Input.GetMouseButton(0) && GUIUtility.hotControl ==0)
)
{
Plane playerPlane = new Plane(Vector3.up, transform.position);
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
float hitdist = 0.0f;
if (playerPlane.Raycast(ray, out hitdist))
{
Vector3 targetPoint = ray.GetPoint(hitdist);
destinationPosition = ray.GetPoint(hitdist);
Quaternion targetRotation = Quaternion.LookRotation(targetPoint - transform.position);
transform.rotation = targetRotation;
//Instantiate (goalPath, destinationPosition, transform.rotation);
// if (goalPath) // Test to see if marker exsists
// {
// Destroy(goalPath); //Destory it now
// Instantiate (goalPath, destinationPosition, transform.rotation); //make new
// }
// else { Instantiate (goalPath, destinationPosition, transform.rotation); } //make new
}
}