Merge branch 'KingNetwork1'

This commit is contained in:
2022-03-23 14:04:36 -05:00
12 changed files with 1045 additions and 28 deletions

View File

@@ -1,6 +1,8 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using MLAPI;
using MLAPI.Messaging;
public class Goo : MonoBehaviour
{
@@ -9,7 +11,7 @@ public class Goo : MonoBehaviour
void FixedUpdate() {
Lifetime++;
if(Lifetime == 850) {
Destruction();
DespawnMyselfServerRPC();
}
}
@@ -22,7 +24,8 @@ public class Goo : MonoBehaviour
}
}
void Destruction() {
Destroy(gameObject);
[ServerRpc(RequireOwnership = false)]
private void DespawnMyselfServerRPC() {
this.gameObject.GetComponent<NetworkObject>().Despawn(true);
}
}

View File

@@ -10,9 +10,11 @@ public class KingPlace : NetworkBehaviour
public GameObject Block;
public GameObject BlockWithoutNetwork;
public GameObject Slime;
public GameObject SlimeWithoutNetwork;
public GameObject HailSprite;
public GameObject HailObject;
public GameObject Slime;
private GameObject Grid;
private GameObject MountGrid;
public GameObject Panel;
@@ -50,7 +52,7 @@ public class KingPlace : NetworkBehaviour
private int Energy = 100;
private GameObject boxPlaced;
private GameObject placedObj;
void Awake()
{
@@ -72,7 +74,7 @@ public class KingPlace : NetworkBehaviour
Avaliable = KAHail.IsAvaliable();
break;
case 2:
Place = Slime;
Place = SlimeWithoutNetwork;
Avaliable = KASlime.IsAvaliable();
break;
}
@@ -123,10 +125,14 @@ public class KingPlace : NetworkBehaviour
if (SlimePlacing == true) {
SlimeDir = DrawArrow();
if (Input.GetMouseButtonUp(0)) {//Reads the player releasing the left mouse button
PlaceTemp.GetComponent<Slime>().GooStart(SlimeDir);
foreach (Transform child in PlaceTemp.transform) {
child.gameObject.SetActive(false);
}
Vector3 slimeLoc = PlaceTemp.transform.position;
Destroy(PlaceTemp);
// PLACE NETWORKED VERSION
SpawnSlimeServerRPC(slimeLoc, SlimeDir);
SlimePlacing = false;
MenuOff();
KASlime.UseItem();
@@ -215,7 +221,7 @@ public class KingPlace : NetworkBehaviour
KABlock.UseItem();
}
if (Place == Slime) {//If Object is Hail or Slime set the respective Placing value to true so it can launch into the secondary placing function
if (Place == SlimeWithoutNetwork) {//If Object is Hail or Slime set the respective Placing value to true so it can launch into the secondary placing function
SlimePlacing = true;
}
else if (Place == HailSprite) {
@@ -365,7 +371,16 @@ public class KingPlace : NetworkBehaviour
[ServerRpc(RequireOwnership = false)]
private void SpawnBoxServerRPC(Vector3 spawnLoc) {
boxPlaced = Instantiate(Block, spawnLoc, Quaternion.identity);
boxPlaced.GetComponent<NetworkObject>().Spawn(null, true);
placedObj = Instantiate(Block, spawnLoc, Quaternion.identity);
placedObj.GetComponent<NetworkObject>().Spawn(null, true);
}
[ServerRpc(RequireOwnership = false)]
private void SpawnSlimeServerRPC(Vector3 spawnLoc, int SlimeDir) {
placedObj = Instantiate(Slime, spawnLoc, Quaternion.identity);
placedObj.GetComponent<Slime>().GooStart(SlimeDir);
placedObj.GetComponent<NetworkObject>().Spawn(null, true);
}
}

View File

@@ -1,8 +1,10 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using MLAPI;
using MLAPI.Messaging;
public class Slime : MonoBehaviour
public class Slime : NetworkBehaviour
{
float MoveSpd;
int GooTimer = 0;
@@ -13,7 +15,6 @@ public class Slime : MonoBehaviour
Vector3 MoveDir = new Vector3(0, 0, 1);
RaycastHit hit;
public GameObject Goo;
public GameObject Folder;
[SerializeField] private LayerMask LayerMask;
// Start is called before the first frame update
void Start()
@@ -29,7 +30,7 @@ public class Slime : MonoBehaviour
if (GooTimer == 6) {
GameObject GooTrail = null;
GooTrail = Instantiate(Goo, transform.position - GooOffset, transform.rotation);
GooTrail.transform.parent = Folder.transform;
GooTrail.GetComponent<NetworkObject>().Spawn(null, true);
GooTimer = 0;
}
//attempt to move forward(Raycast infront for objects, and also raycast down, to make sure there's still ground underneath it)
@@ -40,13 +41,13 @@ public class Slime : MonoBehaviour
GooTimer++;
Lifetime++;
if (Lifetime == 3000)
{
Destruction();
if (Lifetime == 3000) {
DespawnMyselfServerRPC();
}
}
}
//TODO: FIX THIS
void OnTriggerStay(Collider other) {
if (other.tag == "Player") {
//slow down player
@@ -75,8 +76,8 @@ public class Slime : MonoBehaviour
}
}
void Destruction()
{
Destroy(gameObject);
[ServerRpc(RequireOwnership = false)]
private void DespawnMyselfServerRPC() {
this.gameObject.GetComponent<NetworkObject>().Despawn(true);
}
}