O'Reilly logo

Unity AI Game Programming - Second Edition by Thet Naing Swe, Clifford Peters, Aung Sithu Kyaw, Ray Barrera

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Setting up the player tank and aspect

Our 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 the light is centered, or it will not be very helpful for us.

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

using UnityEngine; using System.Collections; public class Target : MonoBehaviour { public Transform targetMarker; 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; ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required