It’s 2D games Plaftormer such Fire and Water Old Flash game
I created a room and a connection to it and after that a level, but when creating characters, their control breaks down
if the character control is performed using the buttons, but the camera and the control itself is shown on the screen of another player and his is mine and how and what to do with it
Please help me with this code
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Photon.Pun;
using UnityEngine.Events;
using Unity.VisualScripting;
public class MovemantMan : MonoBehaviourPun, IPunObservable
{
[SerializeField] private Rigidbody2D rb;
private bool moveleft;
private bool moveright;
private float horizontalMove;
public float speed = 5f;
public float jumpedSpeed = 5f;
private bool isGrounded;
private bool canDoubleJump;
public float delayBeforeDoubleJump;
private SpriteRenderer sr;
private Vector3 smoothMove;
private GameObject sceneCamera;
public GameObject playerCamera;
private void OnEnable()
{
ButtonTrigerCather._myEvent += Mycathcer;
}
private void Mycathcer(string obj)
{
if(photonView.IsMine)
{
switch (obj)
{
case "LeftUp":
moveleft = false;
Debug.Log("Left");
break;
case "RightUp":
moveright = false;
break;
case "LeftDown":
moveleft = true;
break;
case "RightDown":
moveright = true;
break;
case "Jump":
JumpButton();
break;
}
}
}
private void OnDisable()
{
ButtonTrigerCather._myEvent -= Mycathcer;
}
private void Start()
{
rb = GetComponent<Rigidbody2D>();
sr = GetComponent<SpriteRenderer>();
moveleft = false;
moveright = false;
if (photonView.IsMine)
{
playerCamera = GameObject.Find("Main Camera");
sceneCamera = GameObject.Find("Scene Camera");
if (sceneCamera != null)
sceneCamera.SetActive(false);
if (playerCamera != null)
playerCamera.SetActive(true);
}
}
// Input handlers
public void PointerDownLeft()
{
moveleft = true;
}
public void PointerUpLeft()
{
moveleft = false;
}
public void PointerDownRight()
{
moveright = true;
}
public void PointerUpRight()
{
moveright = false;
}
void Update()
{
if (photonView.IsMine)
{
ProcessInputs();
}
else
{
smoothMovement();
}
}
private void ProcessInputs()
{
photonView.RPC("MovePlayer", RpcTarget.Others);
MovePlayer();
}
[PunRPC]
private void MovePlayer()
{
if (moveleft)
{
horizontalMove = -speed;
sr.flipX = true;
}
else if (moveright)
{
horizontalMove = speed;
sr.flipX = false;
}
else
{
horizontalMove = 0;
}
Vector2 move = new Vector2(horizontalMove, rb.velocity.y);
rb.velocity = move;
}
public void JumpButton()
{
if (isGrounded)
{
isGrounded = false;
rb.velocity = Vector2.up * jumpedSpeed;
Invoke(nameof(EnableDoubleJump), delayBeforeDoubleJump);
}
else if (canDoubleJump)
{
rb.velocity = Vector2.up * jumpedSpeed;
canDoubleJump = false;
}
}
private void EnableDoubleJump()
{
canDoubleJump = true;
}
private void smoothMovement()
{
transform.position = Vector3.Lerp(transform.position, smoothMove, Time.deltaTime * 10);
}
public void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info)
{
if (stream.IsWriting)
{
stream.SendNext(transform.position);
}
else if (stream.IsReading)
{
smoothMove = (Vector3)stream.ReceiveNext();
}
}
// Add collision detection to determine if the player is grounded
private void OnCollisionEnter2D(Collision2D collision)
{
if (collision.gameObject.CompareTag("Ground"))
{
isGrounded = true;
canDoubleJump = false; // Reset double jump
}
}
}
``
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
i'm trying everything what i can see in internet help please
New contributor
Oleh T is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.