so I’m making a fps multiplayer and I’ve somehow setup the Hud so when I host/join a match the camera does not switch to the player camera. to combat this problem I added to my player script so when the player spawns it disables the scenecamera switching the default camera to my player. but now when I leave the match the camera doesn’t switch back to the scene camera. I tried adding to my script to enable the camera when my player object in the scene detects player prefab ( the one I use to spawn the player )
has been destroyed, but that just broke because it keeps returning the message of the object being destroyed. Any suggestions?
public class playermovment : MonoBehaviour {
public CharacterController controller;
private float speed = 12f;
public Transform groundcheck;
public float grounddistance = 0.4f;
public LayerMask groundMask;
public float jumphieght = 3f;
public float scopespeed = 5f;
public float normalspeed = 12f;
public float gravaty = 9.8f;
public float crouchspeed = 5f;
private bool iscrouch = false;
public Animator crouchanimation;
Vector3 velocity;
bool isgrounded;
public Camera scene;
public GameObject player;
bool spawned;
void Start()
{
scene.enabled = false;
}
// Update is called once per frame
void Update()
{
isgrounded = Physics.CheckSphere(groundcheck.position, grounddistance, groundMask);
if (isgrounded && velocity.y < 0)
{
velocity.y = -2f;
}
float x = Input.GetAxis("Horizontal");
float z = Input.GetAxis("Vertical");
if (Input.GetButtonDown("Jump") && isgrounded)
{
velocity.y = Mathf.Sqrt(jumphieght * +2f * gravaty);
}
Vector3 move = transform.right * x + transform.forward * z;
controller.Move(move * speed * Time.deltaTime);
velocity.y -= gravaty * Time.deltaTime;
controller.Move(velocity * Time.deltaTime);
if (Input.GetButtonDown("Fire2"))
{
speed = scopespeed;
}
if (Input.GetButtonUp("Fire2"))
{
speed = normalspeed;
}
if (Input.GetKeyDown(KeyCode.LeftShift))
{
iscrouch = !iscrouch;
crouchanimation.SetBool("crouch", iscrouch);
if (iscrouch == false )
{
speed = normalspeed;
}
if (iscrouch == true)
{
speed = crouchspeed;
}
}
if( player != null)
{
spawned = true;
}
if (player == null && spawned == true)
{
Debug.Log("destroyed");
scene.enabled = true;
}
}
}