- Home /
Script finding a none-existing player clone
Hi!
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);
}
}
Answer by Lev-Lukomskyi · Oct 25, 2014 at 07:30 PM
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.
I know but I want to find it. I need the camera to find the player after he respawns.
Answer by skylem · Feb 03, 2015 at 04:48 AM
I had this error too its what brought me here but i happened to think of a solution use the following
playerTrans = FindObjectOfType<PlayerControl> ().transform;
fill () with a unique script or component that is upon your character.