TheKingsRace/Assets/Scripts/Environment/BoulderSpawn.cs
Vincent Wheat bf2acec8d0 AngryAboutIt
Kinda mad about it >:(
2022-04-04 12:08:45 -05:00

54 lines
1.5 KiB
C#

using MLAPI;
using MLAPI.Messaging;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class BoulderSpawn : NetworkBehaviour
{
[SerializeField] private float RespawnTimer = 10.0f;
[SerializeField] private float InitialSpawnDelay = 0.0f;
private float currentTime = 0.0f;
[SerializeField] private float boulderScaleMultiplier = 1.0f;
[SerializeField] private Vector3 spawnForce;
[SerializeField] private Vector3 SpawnLocation;
[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.transform.localScale *= boulderScaleMultiplier;
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 + InitialSpawnDelay)
{
currentTime = 0.0f;
InitialSpawnDelay = 0.0f;
SpawnBoulderServerRPC();
}
}
}