Fixed Blocks Not Placing For Clients

This commit is contained in:
2022-02-04 20:02:55 -06:00
parent 215d709915
commit b278e511ff
6 changed files with 174 additions and 35 deletions

View File

@@ -19,7 +19,6 @@ public class GridReveal : MonoBehaviour
for (int i = Rows.Length-1; i > ROSCount-1; i--) {// Disables most of the Rows that the King can't see
Rows[i].SetActive(false);
}
gameObject.SetActive(false);
}
public void GridSwitch(bool State) {//Activates or deactivates the Grid

View File

@@ -15,6 +15,18 @@ public class KingMove : MonoBehaviour
Grid = GameObject.FindGameObjectWithTag("KingGrid");
}
void Start()
{
// Turn on the king grid after a couple seconds. Allows scripts to grab their reference to it before it is disabled
StartCoroutine(TurnOffGridAtStartOfMatch());
}
IEnumerator TurnOffGridAtStartOfMatch()
{
yield return new WaitForSecondsRealtime(0.5f);
Grid.GetComponent<GridReveal>().GridSwitch(false);
}
// Update is called once per frame
void Update() {
float translation = Input.GetAxis("KingMove") * speed;

View File

@@ -1,9 +1,10 @@
using System.Collections;
using System.Collections.Generic;
using MLAPI;
using MLAPI.Messaging;
using UnityEngine;
public class KingPlace : MonoBehaviour
public class KingPlace : NetworkBehaviour
{
//Is called when the King clicks on the Block button
@@ -23,12 +24,14 @@ public class KingPlace : MonoBehaviour
public GameObject Thunderstorm;
//Is called when the King clicks on the Thunderstorm button
public void OnThundClicked() {
public void OnThunderClicked() {
//TODO Spawn thunderstorms on the players
}
public GameObject Block;
public GameObject BlockWithoutNetwork;
public GameObject HailSprite;
public GameObject HailObject;
public GameObject Slime;
@@ -53,7 +56,7 @@ public class KingPlace : MonoBehaviour
//Switch statement, ID-0 = Block,ID-1 = Hail,ID-2 = Slime
switch (ID) {//Parses in the button clicked into the right object that the King is placing
case 0:
Place = Block;
Place = BlockWithoutNetwork;
break;
case 1:
Place = HailSprite;
@@ -108,7 +111,6 @@ public class KingPlace : MonoBehaviour
int Box = (int)y; //Rounds it down
int x = (RowNumb * -BoxSize) + 101;//Sets it's X to the X of the Row
int z = (Box * -BoxSize) + 906;//Sets its Z to the Z of the Box
//PlaceTemp.transform.position = new Vector3(x, PlaceTemp.transform.position.y, z);//fully snaps it to the grid
// Grid Check first for valid location
GridCheck(RowNumb, Box, ref FirstPlacing);//Makes sure the Box is a valid position
@@ -116,9 +118,11 @@ public class KingPlace : MonoBehaviour
// Instantiate a networked box at the position
if (FirstPlacing == false)
{
// Calculate the position to spawn at
Vector3 spawnLoc = new Vector3(x, PlaceTemp.transform.position.y, z);
boxPlaced = Instantiate(PlaceTemp, spawnLoc, Quaternion.identity);
boxPlaced.GetComponent<NetworkObject>().Spawn(null, true);
// Have the server spawn the box
SpawnBoxServerRPC(spawnLoc);
// Remove the reference to PlaceTemp
Destroy(PlaceTemp);
@@ -164,4 +168,9 @@ public class KingPlace : MonoBehaviour
}
}
[ServerRpc(RequireOwnership = false)]
private void SpawnBoxServerRPC(Vector3 spawnLoc) {
boxPlaced = Instantiate(Block, spawnLoc, Quaternion.identity);
boxPlaced.GetComponent<NetworkObject>().Spawn(null, true);
}
}