//Add different components to the game objects depending on if they're staying or not void AddComponent(GameObject obj, bool stay) { obj.gameObject.layer = 8; obj.AddComponent <BoxCollider>(); obj.GetComponent <BoxCollider>().size = new Vector3(obj.GetComponent <BoxCollider>().size.x, 0, obj.GetComponent <BoxCollider>().size.z); obj.GetComponent <BoxCollider>().center = new Vector3(obj.GetComponent <BoxCollider>().center.x, 0, obj.GetComponent <BoxCollider>().center.z); BoxCollider bcol = obj.AddComponent <BoxCollider>(); bcol.isTrigger = true; if (!stay) { obj.AddComponent <Rigidbody>(); obj.GetComponent <Rigidbody>().interpolation = RigidbodyInterpolation.Interpolate; obj.GetComponent <Rigidbody>().AddExplosionForce(100, obj.transform.position, 20); Destroy(obj, 3f); } else { obj.AddComponent <Sliceable>(); Sliceable temp = obj.GetComponent <Sliceable>(); temp.SetMaster(this); temp.SetGameStarted(true); _gm.SetSliceable(temp); } }
//Starts the game and lets the knife and sliceable know public void StartGame() { _knife.SetGameStarted(true); _sliceable.SetGameStarted(true); }