Question by
habssun · Oct 28, 2019 at 07:11 PM ·
camera2d gamemultiplayer-networking
Camera in untiy2D mulitplayer/networking
so i spent my day looking for a solution but nothing seems working.. what am i doing wrong ? i had thhe player as a prefab and everytime the second player spawns the camera ignore the first plyaer here is camera Code:
public class CameraFollow : NetworkBehaviour {
public float interpVelocity;
public float minDistance;
public float followDistance;
public GameObject target;
public Vector3 offset;
Vector3 targetPos;
// Use this for initialization
void Start () {
targetPos = transform.position;
}
// Update is called once per frame
void FixedUpdate () {
if(isLocalPlayer){
if (target)
{
Vector3 posNoZ = transform.position;
posNoZ.z = target.transform.position.z;
Vector3 targetDirection = (target.transform.position - posNoZ);
interpVelocity = targetDirection.magnitude * 5f;
targetPos = transform.position + (targetDirection.normalized * interpVelocity * Time.deltaTime);
transform.position = Vector3.Lerp( transform.position, targetPos + offset, 0.25f);
}
}else
return;
}
}
Comment
Best Answer
Answer by habssun · Oct 29, 2019 at 02:42 PM
i found a soultion, just add this code to my player:
public class CameraCheck : NetworkBehaviour
{
// Start is called before the first frame update
public Camera cam;
void Start()
{
}
// Update is called once per frame
void Update()
{
if(isLocalPlayer){
}else{
cam.enabled = false;
}
}
}
Your answer
Follow this Question
Related Questions
MLAPI - Lost with instantiate 1 Answer
2D box collider always detecting player,2D Box colliders detecting player when he is not there 1 Answer
How to scale Character/ Sprite size relative to camera?,How to make sprite bigger towards camera? 0 Answers
camera not following target after reload 0 Answers
Rect or Camera transform? 0 Answers