private void Spawn() { // go over list of ball rotations and instantiate ball prefabs at calculated positions. for (int i = 0; i < whiteBallRotations.Count; i++) { WhiteBallObject projectile = Instantiate(whiteBallPrefab, spawnPosition, Quaternion.identity).GetComponent <WhiteBallObject>(); projectile.transform.RotateAround(transform.position, new Vector3(0, 0, 1), whiteBallRotations[i]); // set active to prevent whiteball projectile from colliding with this object. projectile.SetActive(false); projectile.SetParent(transform); } }
private void LaunchBalls() { WhiteBallObject[] whiteBallObjects = gameObject.GetComponentsInChildren <WhiteBallObject>(); for (int i = 0; i < whiteBallObjects.Length; i++) { WhiteBallObject aux = whiteBallObjects[i]; // make collider active. aux.SetActive(true); // set color to be the same as this ball's. aux.SetColor(GetComponent <SpriteRenderer>().material.color); // detach from parent aux.SetParent(null); // set direction and speed parameters aux.SetProjectileDirection(aux.transform.position - transform.position); aux.SetSpeed(15f); } }