- Home /
Problem is not reproducible or outdated
look at closer
hey everyone, i need some help, i want my capsule look at cube, but i want look at cube closer to my capsule, i just know script : transform.LookAt ("Cube");
, but it's not look at closer to my capsule, so i need help to look at closer to my capsule. I've been looking for a solution on youtube, but did not find any solution thanks,
Answer by GamezAtWork · May 13, 2017 at 08:07 AM
Is the amount of cubes always the same, or set from the start?
If so, an easy way to do this is to store all the cubes in an array on your script (and set them through the inspector), and do a distance check across them to find which is the closest, followed by doing a transform.lookat to that closest cube.
(Even if it isn't, you can apply a similar method, you just need to update that array of cubes, and most likely use a List instead of a static array)
can you give me exampel, Can you give me an example, because I just started on unity3d