The player's tank and the aspect class

The Target object is a simple sphere object with the mesh render disabled. We have also created a point light and made it a child of our Target object. Make sure that the light is centered, or it will not be very helpful.

Look at the following code in the Target.cs file:

using UnityEngine; 
 
public class Target : MonoBehaviour { 
 
    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;                transform.position = targetPosition;            }        }    }
} 

Attach this ...

Get Unity Artificial Intelligence Programming - Fourth Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.