I am trying to create a multiplayer game with two players where each requires their own camera. The can’t simply be parented to the player because I don’t want Player rotation to affect the camera.
Right now it works when there is one host and no clients. When there is both a host and client, the cameras follow the client player in both games.
I have looked about and have found results such as
where I used jah0’s reply as a starting point but I seem to have gotten stuck
I also looked at
https://forum.unity3d.com/threads/network-camera-multiplayer.73162/
and some info on the API Unity - Scripting API: Network.OnNetworkInstantiate(NetworkMessageInfo)
Here is the code I am currently using
using UnityEngine;
public class CameraFollow : MonoBehaviour {
public Transform playerTransform; //always gets the same player, use an array instead
public int depth = 8;
public int height = 10; //y component
// Update is called once per frame
void Update() {
if (playerTransform != null) {
transform.position = new Vector3(playerTransform.position.x - depth, height, 0);
}
}
public void SetTarget(Transform target) {
playerTransform = target;
}
}
Here is what I’m doing with the player (excerpt)
public override void OnStartLocalPlayer() {
Camera.main.GetComponent<CameraFollow>().SetTarget(gameObject.transform);
}
I appreciate any and all help.