Make an object follow the players whenever the camera turns away from the object

Hello!
This is my first post so sorry if its sloppy
Basically I’m making a game that requires a script a bit inspired by super mario ghosts

an object following a players, whenever the player doesn’t look

So, it’s a bit more complex but I think we can work out a soltuion
Basically I got a big map, I want a randomizer from that gives me a 10% chance that the object spawns behind me, aka the ghost
And whenever I don’t look in his direction, he comes one meter closer
Not like walking, but like teleporting that one meter.
And whenever I look, he stands still
And whenever I come near him like a radius of one meter
HE backs up 3 meters
The thing is that I got a script that on collision teleport me to one of 75 possible waypoints or more out of a list
I still want him to be able to follow me after I teleported maybe half the map away from him
Is that possible, and if yes, how?
**thanks for all the answers in advance!
Cheers! **

This is a pretty broad question as far as helping you out with a specific implementation, but it sounds like you need to start with a pretty simple detection script that can tell if the player is facing the object or not.

public class SneakyGhost : Monobehavior{

    public GameObject player;
    public float maxDetectionDistance = 50;
    public float maxDetectionAngle = 90;

    void Update(){

        bool playerIsFacing = PlayerIsFacing();

        if(playerIsFacing){
            //maybe move away if player is too close, otherwise
            //stop movement
        }
        else{
            //move towards player
        }
    }

    bool PlayerIsFacing(){

        //Check if we are within range of the player
        if(Vector3.Distance(player.transform.position, transform.position) > maxDetectionDistance){
            return false;
        }

        //Get the direction from the player to the objects position
        Vector3 myDirection = transform.position - player.transform.position;
        myDirection.y = 0; //Only take into account the horizontal components


        //Get the direction the player is facing in
        Vector3 playerDirection = player.transform.forward;
        playerDirection.y = 0; //Only take into account the horizontal components

        //Check if the direction we are in is within the player's FOV
        if(Vector3.Angle(myDirection, playerDirection) < maxDetectionAngle){
            return true;
        }

        return false;
    }
}

You will have to add your own movement based on what you want the object to do, and may want to make the direction detection more fancy based on your needs, but this should get you started at least