How to make objects facing towards player in Unity



Some of elements in our game probably need to always face towards the player or player’s camera.

With this script we can make any object that this script attached on it, to look at a specific object, like player object or a camera.

Here is the simple script:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class LookAtPlayer : MonoBehaviour
{
	
	public GameObject player;
	
    // Start is called before the first frame update
    void Start()
    {
        
    }

    // Update is called once per frame
    void Update()
    {
        transform.LookAt(player.transform);
    }
}

To download the sample file including this script in a single unitypackage file, click this link: https://drive.google.com/open?id=1qpp1Ha0hqJxRAVTt7QpqvNvP7HmFLsvR

loading...

Leave a Reply

Your email address will not be published. Required fields are marked *