mirror of
https://github.com/Kaveinator/NetickProForUnity.git
synced 2025-10-26 17:59:07 -07:00
auto
This commit is contained in:
30
Samples~/First Person Shooter/Scripts/FPSEventsHandler.cs
Normal file
30
Samples~/First Person Shooter/Scripts/FPSEventsHandler.cs
Normal file
@@ -0,0 +1,30 @@
|
||||
using UnityEngine;
|
||||
using Netick;
|
||||
using Netick.Unity;
|
||||
|
||||
namespace Netick.Samples.FPS
|
||||
{
|
||||
public class FPSEventsHandler : NetworkEventsListener
|
||||
{
|
||||
public Transform SpawnPos;
|
||||
public GameObject PlayerPrefab;
|
||||
|
||||
// This is called to read inputs.
|
||||
public override void OnInput(NetworkSandbox sandbox)
|
||||
{
|
||||
var input = sandbox.GetInput<FPSInput>();
|
||||
|
||||
input.Movement = new Vector2(Input.GetAxis("Horizontal"), Input.GetAxis("Vertical"));
|
||||
input.ShootInput |= Input.GetMouseButton(0);
|
||||
sandbox.SetInput<FPSInput>(input);
|
||||
}
|
||||
|
||||
// This is called on the server when a player has connected.
|
||||
public override void OnPlayerConnected(NetworkSandbox sandbox, NetworkPlayer networkPlayer)
|
||||
{
|
||||
var spawnPos = SpawnPos.position + Vector3.left * (1 + sandbox.ConnectedPlayers.Count);
|
||||
var player = sandbox.NetworkInstantiate(PlayerPrefab, spawnPos, Quaternion.identity, networkPlayer).GetComponent<FPSController>();
|
||||
networkPlayer.PlayerObject = player.gameObject;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user