| | | 1 | | /* |
| | | 2 | | * |
| | | 3 | | * Code by: |
| | | 4 | | * Dimitrios Vlachos |
| | | 5 | | * djv1@student.london.ac.uk |
| | | 6 | | * dimitri.j.vlachos@gmail.com |
| | | 7 | | * |
| | | 8 | | */ |
| | | 9 | | |
| | | 10 | | using System.Collections; |
| | | 11 | | using System.Collections.Generic; |
| | | 12 | | using UnityEngine; |
| | | 13 | | |
| | | 14 | | public class UI_FacePlayer : MonoBehaviour |
| | | 15 | | { |
| | | 16 | | Camera cam; |
| | | 17 | | // Start is called before the first frame update |
| | | 18 | | void Start() |
| | 1 | 19 | | { |
| | 1 | 20 | | cam = Camera.main; |
| | 1 | 21 | | } |
| | | 22 | | |
| | | 23 | | // Update is called once per frame |
| | | 24 | | void Update() |
| | 1682 | 25 | | { |
| | 1682 | 26 | | TurnToCamera(); |
| | 1682 | 27 | | } |
| | | 28 | | |
| | | 29 | | void TurnToCamera() |
| | 1682 | 30 | | { |
| | | 31 | | // Get the direction to look |
| | 1682 | 32 | | Vector3 v = cam.transform.position - transform.position; |
| | | 33 | | // Cancel the other directions of rotation |
| | 1682 | 34 | | v.x = v.z = 0.0f; |
| | | 35 | | |
| | | 36 | | // Turn to the camera |
| | 1682 | 37 | | transform.LookAt(cam.transform.position - v); |
| | 1682 | 38 | | transform.Rotate(0, 180, 0); |
| | 1682 | 39 | | } |
| | | 40 | | } |