private IEnumerator SpawnBall(Ball ball) { //Get ball object from the object pool. GameObject enemy = ObjectPooler.sharedInstance.GetPooledObject("Enemy"); if (enemy != null) { BallHealth enemyHealth = enemy.GetComponent <BallHealth>(); Rigidbody rigid = enemy.GetComponent <Rigidbody>(); Vector3 randomSize = Stats.sharedInstance.GetRandomSize(); enemy.transform.localScale = randomSize; //The enemies are set active outside of the gamefield to mark them as in use. //Gravity is disabled to prevent them from falling for eternity before they are spawned. rigid.useGravity = false; enemy.layer = 11; enemyHealth.health = ball.hp; enemyHealth.splits = ball.splits; enemy.SetActive(true); yield return(new WaitForSeconds(ball.delay)); //After the respective delay, start the coroutine to move the ball //into the gamefield either from the left wall or the right wall, //chosen randomly. StartCoroutine(MoveToPosition(enemy, 2f, rigid)); } }
// Use this for initialization // Update is called once per frame void Start() { rb = GetComponent <Rigidbody2D> (); balls = GameObject.FindObjectOfType <BallController>(); gm = GameObject.FindGameObjectWithTag("GM").GetComponent <GameMaster>(); ballHealth = GameObject.FindGameObjectWithTag("Player").GetComponent <BallHealth>(); moveDirection = (balls.transform.position - transform.position).normalized * moveSpeed; rb.velocity = new Vector2(moveDirection.x, moveDirection.y); Destroy(gameObject, 3f); }
void SpawnSplit(int hp, Vector3 explosionPos, Vector3 newSize, bool left) { //Grab new enemies from the pool to be used as the splits. GameObject enemy = ObjectPooler.sharedInstance.GetPooledObject("Enemy"); if (enemy != null) { BallHealth enemyHealth = enemy.GetComponent <BallHealth>(); Rigidbody rigid = enemy.GetComponent <Rigidbody>(); enemy.transform.position = explosionPos; enemy.transform.localScale = newSize; enemyHealth.health = hp; enemyHealth.splits = null; enemy.SetActive(true); //On Explosion, add an up force to both splits. Add a left force to one //and a right force to the other. Vector3 splitForce = (left ? Vector3.left + Vector3.up : Vector3.right + Vector3.up) * splitForceOffset; rigid.AddRelativeForce(splitForce); } }
void Start() { bp = GameObject.FindGameObjectWithTag("GM").GetComponent <GameMaster>(); ball = GameObject.FindGameObjectWithTag("Player").GetComponent <BallHealth>(); }
void Start() { ballHealth = GetComponent <BallHealth>(); ballFire = GetComponent <Skill_Fire>(); }