Our Target object is a simple sphere game object with the mesh render removed, so that we end up with only the Sphere Collider.
Look at the following code in the Target.cs file:
using UnityEngine;
public class Target : MonoBehaviour
{
public Transform targetMarker;
void Start (){}
void Update ()
{
int button = 0;
//Get the point of the hit position when the mouse is being clicked
if(Input.GetMouseButtonDown(button))
{
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
RaycastHit hitInfo;
if (Physics.Raycast(ray.origin, ray.direction, out hitInfo))
{
Vector3 targetPosition = hitInfo.point;
targetMarker.position = targetPosition;
}
}
}
}
You'll notice we left in an empty Start method in the...