Characters
This commit is contained in:
44
Game/Scripts/Networking/SteamLocalInputSender.cs
Normal file
44
Game/Scripts/Networking/SteamLocalInputSender.cs
Normal file
@@ -0,0 +1,44 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace MegaKoop.Game.Networking
|
||||
{
|
||||
[DisallowMultipleComponent]
|
||||
public class SteamLocalInputSender : MonoBehaviour
|
||||
{
|
||||
[SerializeField] private SteamCharacterNetworkBridge characterNetwork;
|
||||
[SerializeField] private float sendInterval = 0.05f;
|
||||
|
||||
private float sendTimer;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
if (characterNetwork == null)
|
||||
{
|
||||
characterNetwork = GetComponent<SteamCharacterNetworkBridge>();
|
||||
}
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
if (characterNetwork == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (!characterNetwork.IsLocalPlayer || characterNetwork.IsAuthority)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
sendTimer -= Time.deltaTime;
|
||||
Vector2 moveInput = new Vector2(Input.GetAxisRaw("Horizontal"), Input.GetAxisRaw("Vertical"));
|
||||
bool jumpPressed = Input.GetButtonDown("Jump");
|
||||
|
||||
if (sendTimer <= 0f || jumpPressed)
|
||||
{
|
||||
characterNetwork.SendLocalInput(moveInput, jumpPressed);
|
||||
sendTimer = sendInterval;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user