How to make a gameobject always face towards another? (tidally locked)

Hello, everyone. The title explains it all. How would I make an object always facing towards another object (like the Moon always faces the Earth)? All the methods I found were outdated and don’t work anymore. Thanks for your help!

It is first what is pops on my mind:

p.s - guys check this little Lego Batman passing near cubes, omg so cute!
118789-unity-funny-lookat2.gif


using UnityEngine;
using System.Collections;

public class ExampleClass : MonoBehaviour
{
    public GameObject Moon;
    public GameObject Sun;

    void Update()
    {
        // Rotate the camera every frame so it keeps looking at the target
        Moon.transform.LookAt(Sun.transform);
        Sun.transform.LookAt(Moon.transform);
    }
}

You can try using RotateTowards.

In your code you can create a public GameObject target or make it a public Transform target. Also make a game object for the one that seeks a position/rotation to face like public GameObject moon. Then in an Update() method you would write something like this: moon.Transform.rotation=Quaternion.RotateTowards(moon.Transform.rotation,target.Transform.rotation,float time) where here the method uses the original rotation of your Moon or whatever you want to rotate, and it rotates towards the target which can be your Earth. In the inspector you’ll need to drag and drop in the appropriate gameobjects/prefabs.

This is just a guess, I haven’t ran any code yet to back up my answer; give it a shot and see what happens @TheEmeraldRuby .