forked from Serinoxxx/NGOAC
-
Notifications
You must be signed in to change notification settings - Fork 0
/
NetworkWeaponSpawner.cs
37 lines (31 loc) · 1.07 KB
/
NetworkWeaponSpawner.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
using MalbersAnimations.Weapons;
using Unity.Netcode;
using UnityEngine;
namespace MalbersAnimations.NetCode
{
public class NetworkWeaponSpawner : NetworkBehaviour
{
[SerializeField] private GameObject weaponPrefab;
[SerializeField] private Transform spawnPoint;
public void Spawn()
{
Debug.Log("Check is server");
if (!IsServer) return;
Debug.Log("Check has weapon prefab");
if (!weaponPrefab) return;
Debug.Log("Get random number");
int randomNumber = Random.Range(100000, 999999);
Debug.Log("SpawnRPC");
SpawnRPC(randomNumber);
}
[Rpc(SendTo.ClientsAndHost)]
public void SpawnRPC(int networkWeaponID)
{
Debug.Log("Spawned RPC");
var newWeapon = GameObject.Instantiate(weaponPrefab, spawnPoint.position, spawnPoint.rotation);
//Set the weapon ID to a unique value
var weapon = newWeapon.GetComponent<NetworkWeapon>();
weapon.networkID = networkWeaponID;
}
}
}