void Start() { // retrieving the playerShip and playerShipBroken objects for (int i = 0; i < transform.childCount; i++) { GameObject child = transform.GetChild(i).gameObject; if (child.tag == GameManager.Instance.GetPlayerShipTag()) { playerShip = child; } else if (child.tag == GameManager.Instance.GetPlayerShipBrokenTag()) { playerShipBroken = child; } } shipCollider = playerShip.GetComponent <BoxCollider>(); shipCollider.enabled = false; // storing the original fragment local position fragmentPositions = new Vector3[playerShipBroken.transform.childCount]; for (int i = 0; i < playerShipBroken.transform.childCount; i++) { GameObject child = playerShipBroken.transform.GetChild(i).gameObject; if (child.tag == GameManager.Instance.GetShipModuleTag()) { RandomSpacePusher randomPusher = child.GetComponent <RandomSpacePusher>(); randomPusher.SetRandomPush(fragmentsPushForce, fragmentsAngularVelocity); fragmentPositions[i] = child.transform.localPosition; } } }
private void SpawnAsteroid(Vector3 spawnPosition, AsteroidData asteroidData) { GameObject asteroid = PoolsManager.Instance.GetAsteroidsPool().GetAvailable(); asteroid.transform.position = spawnPosition; asteroid.transform.rotation = Random.rotation; asteroid.SetActive(true); Rigidbody asteroidRB = asteroid.GetComponent <Rigidbody>(); asteroidRB.mass = asteroidData.GetMass(); RandomSpacePusher randomPusher = asteroid.GetComponent <RandomSpacePusher>(); randomPusher.SetRandomPush(pushForce, angularVelocity); randomPusher.GivePush(); AsteroidController asteroidController = asteroid.GetComponent <AsteroidController>(); asteroidController.Init(asteroidData); }