Time for actioning – attach the LookAtPlayer camera script
This simple script makes the camera look at Player. The camera does not move. It simply rotates so it's always looking at Player no matter how close or far away it is.
Attach this script to LookAt Camera in the Hierarchy panel:
What just happened?
Let us analyze the code that we just saw:
Line 6: private Transform playerPosition;
- The variable
playerPosition
will store theTransform
information of Player - This means that every frame, the
Transform
x, y, z position of Player is updated and stored in the variableplayerPosition
Line 10: playerPosition = GameObject.Find("Player").transform;
- In order ...
Get Learning C# by Developing Games with Unity 3D Beginner's Guide 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.