I am making a simple player follow script and it is not working. When I checked what it is finding, it is finding “Player(Clone)”. There is no clone in the scene or in the prefabs. Why is it doing this?
My code.
using UnityEngine;
using System.Collections;
public class CameraFollow : MonoBehaviour {
public GameObject target;
void Start(){
target = GameObject.FindGameObjectWithTag("Player");
}
void Update(){
transform.position = new Vector3(target.transform.position.x, target.transform.position.y, -10);
}
}
I dont know why there is Player(Clone), but you can solve your problem another way:
You can link your Player obj directly:
using UnityEngine;
public class CameraFollow : MonoBehaviour
{
public Transform playerTrans;
void Update()
{
transform.position = new Vector3(playerTrans.position.x, playerTrans.position.y, -10);
}
}
Or you can simply make camera obj child of your Player obj.