- Home /
Question by
foruniv00 · Jun 04 at 03:06 PM ·
camerainstantiateclone
How to make camera follow to clone player not first production ?
Hi. I made the code which can follow the clone player. But It worked only the first clone player. If join room second or later, It can't find clone player and doesn't work. How can I fix that ? Thanks for anything your helps.
follow.cs
private void Awake()
{
mainCam = this;
}
void Start()
{
height = Camera.main.orthographicSize;
width = height * Screen.width / Screen.height;
}
void LateUpdate()
{
if (player == null)
{
player = GameObject.Find("Player(Clone)");
}
else
{
//transform.position = new Vector3(target.position.x, target.position.y, -10f);
transform.position = Vector3.Lerp(transform.position, target.position, Time.deltaTime * speed);
float lx = size.x * 0.5f - width;
float clampX = Mathf.Clamp(transform.position.x, -lx + center.x, lx + center.x);
float ly = size.y * 0.5f - height;
float clampY = Mathf.Clamp(transform.position.y, -ly + center.y, ly + center.y);
transform.position = new Vector3(clampX, clampY, -10f);
}
}
player spawn script
public void Spawn()
{
GameObject PI = PhotonNetwork.Instantiate("Player", Vector3.zero, Quaternion.identity);
Follow.mainCam.target = PI.transform;
Debug.Log("I'm in the room.");
}
Comment
Your answer
Follow this Question
Related Questions
How to follow clone object with camera. 5 Answers
How do I make an object clone itself? 1 Answer
How to add multiple clones of an object to a list ? Currently only 1 clone gets added. 1 Answer
Instantiated Component not Cloning Parent Classes? 1 Answer
Having an issue with instantiating objects on button clicks 1 Answer