mirror of
https://github.com/Leahnaya/TheKingsRace.git
synced 2026-09-09 10:55:17 -05:00
Merge branch 'ResetButton'
This commit is contained in:
45
Assets/Scripts/Environment/ResetZonesGlobal.cs
Normal file
45
Assets/Scripts/Environment/ResetZonesGlobal.cs
Normal file
@@ -0,0 +1,45 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using MLAPI;
|
||||
using MLAPI.Messaging;
|
||||
|
||||
public class ResetZonesGlobal : MonoBehaviour {
|
||||
|
||||
private bool cooldown = false;
|
||||
|
||||
[SerializeField]
|
||||
private int RespawnZone;
|
||||
|
||||
private void OnTriggerEnter(Collider other) {
|
||||
if (cooldown == false && other.transform.gameObject.tag == "PlayerTrigger" && other.gameObject.transform.root.gameObject.GetComponent<NetworkObject>().OwnerClientId == NetworkManager.Singleton.LocalClientId) {
|
||||
SetClientRespawnZoneServerRPC(other.gameObject.transform.root.gameObject.GetComponent<NetworkObject>().OwnerClientId, RespawnZone);
|
||||
cooldown = true;
|
||||
StartCoroutine(CoolItDown());
|
||||
}
|
||||
}
|
||||
|
||||
[ServerRpc(RequireOwnership = false)]
|
||||
private void SetClientRespawnZoneServerRPC(ulong clientID, int RespawnZone) {
|
||||
SetClientRespawnZoneClientRPC(clientID, RespawnZone);
|
||||
}
|
||||
|
||||
[ClientRpc]
|
||||
private void SetClientRespawnZoneClientRPC(ulong clientID, int RespawnZone) {
|
||||
// Get all players in the scene
|
||||
GameObject[] playableCharacters = GameObject.FindGameObjectsWithTag("Player");
|
||||
|
||||
// Find our player first
|
||||
foreach (GameObject character in playableCharacters) {
|
||||
if (character.GetComponent<NetworkObject>().OwnerClientId == clientID) {
|
||||
// Set their zone
|
||||
character.GetComponent<ResetZones>().SetCurrentZone(RespawnZone);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
IEnumerator CoolItDown() {
|
||||
yield return new WaitForSecondsRealtime(1f);
|
||||
cooldown = false;
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/Environment/ResetZonesGlobal.cs.meta
Normal file
11
Assets/Scripts/Environment/ResetZonesGlobal.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6560db454bf09ef49bdb0240a370b8aa
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user