-
Notifications
You must be signed in to change notification settings - Fork 0
/
BaseObject.cs
95 lines (75 loc) · 2.37 KB
/
BaseObject.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Networking;
public class BaseObject : NetworkBehaviour
{
[SyncVar]
public bool EffectedByExplosion;
[SyncVar]
public int indexCounter;
[SyncVar]
public int StressAmount;
public GameObject ItemObject;
GameObject SpawnedItemObject;
BaseItem ItemClass;
int playIndex;
Vector3[] VectorDirection = new Vector3[4];
// Start is called before the first frame update
void Start()
{
VectorDirection[0] = Vector3.up;
VectorDirection[1] = -(Vector3.up);
VectorDirection[2] = Vector3.left;
VectorDirection[3] = -(Vector3.left);
//Spawnfrectures();
indexCounter = 0;
playIndex = 0;
}
// Update is called once per frame
void Update()
{
if (EffectedByExplosion == true && indexCounter >= StressAmount)
{
if (playIndex <= 0)
{
int CaniSpawn = Random.Range(0, 2);
Spawnfrectures();
Spawnfrectures();
playIndex++;
if (CaniSpawn == 0)
{
CmdSpawnItem();
}
}
}
}
public void Spawnfrectures()
{
int RandIndex = Random.Range(0, 4);
GameObject[] gameObjects = MeshCut.Cut(gameObject, transform.position, VectorDirection[RandIndex], GetComponent<MeshRenderer>().material);
for (int i = 0; i < gameObjects.Length; i++)
{
if (gameObjects[i].GetComponent<Rigidbody>() == null)
{
Rigidbody rb = gameObjects[i].AddComponent<Rigidbody>();
BoxCollider bc = gameObjects[i].AddComponent<BoxCollider>();
rb.mass = 10;
Destroy(gameObjects[i], 8f);
}
}
GetComponent<Rigidbody>().mass = 10;
BoxCollider CurrentBC = GetComponent<BoxCollider>();
Destroy(CurrentBC);
BoxCollider newwBC = gameObject.AddComponent<BoxCollider>();
Destroy(gameObject, 8f);
}
[Command]
void CmdSpawnItem()
{
SpawnedItemObject = Instantiate(ItemObject, transform);
ItemClass = SpawnedItemObject.GetComponent<BaseItem>();
ItemClass.TypeOfItem = Random.Range(0, 3);
NetworkServer.Spawn(SpawnedItemObject);
}
}