using UnityEngine; public class FollowPlayer : MonoBehaviour { private GameObject player; // Start is called once before the first execution of Update after the MonoBehaviour is created void Start() { player = GameObject.Find("Player"); if (!player) return; SetLocation(); SetRotation(); } // Update is called once per frame void Update() { SetLocation(); SetRotation(); } private void SetLocation() { gameObject.transform.position = new Vector3(player.transform.position.x, gameObject.transform.position.y, player.transform.position.z); } private void SetRotation() { gameObject.transform.rotation = Quaternion.Euler(gameObject.transform.rotation.eulerAngles.x, player.transform.rotation.eulerAngles.y, player.transform.rotation.eulerAngles.z); } }