mirror of
https://github.com/Leahnaya/TheKingsRace.git
synced 2026-09-12 04:15:16 -05:00
Finished Networking the Boulder
This commit is contained in:
@@ -1,8 +1,10 @@
|
||||
using MLAPI;
|
||||
using MLAPI.Messaging;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class BoulderSpawn : MonoBehaviour
|
||||
public class BoulderSpawn : NetworkBehaviour
|
||||
{
|
||||
[SerializeField] private float RespawnTimer = 10.0f;
|
||||
private float currentTime = 0.0f;
|
||||
@@ -13,22 +15,32 @@ public class BoulderSpawn : MonoBehaviour
|
||||
|
||||
[SerializeField] private Transform BoulderPrefab;
|
||||
private GameObject boulderInScene;
|
||||
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
if (IsHost)
|
||||
{
|
||||
SpawnBoulderServerRPC();
|
||||
}
|
||||
}
|
||||
|
||||
[ServerRpc(RequireOwnership = false)]
|
||||
private void SpawnBoulderServerRPC() {
|
||||
boulderInScene = Instantiate(BoulderPrefab, SpawnLocation, Quaternion.identity).gameObject;
|
||||
boulderInScene.GetComponent<Rigidbody>().AddForce(spawnForce);
|
||||
boulderInScene.GetComponent<NetworkObject>().Spawn(null, true);
|
||||
boulderInScene.GetComponent<Boulder>().StartCountdown((int)RespawnTimer, spawnForce);
|
||||
}
|
||||
|
||||
private void FixedUpdate()
|
||||
{
|
||||
if (!IsHost) { return; }
|
||||
|
||||
currentTime += Time.fixedDeltaTime;
|
||||
if (currentTime >= RespawnTimer)
|
||||
{
|
||||
currentTime = 0.0f;
|
||||
Destroy(boulderInScene);
|
||||
boulderInScene = Instantiate(BoulderPrefab, SpawnLocation, Quaternion.identity).gameObject;
|
||||
boulderInScene.GetComponent<Rigidbody>().AddForce(spawnForce);
|
||||
SpawnBoulderServerRPC();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user