/// <summary> /// Use this for initialization /// </summary> void Start() { // spawn and destroy ball to calculate // spawn location min and max GameObject tempBall = Instantiate <GameObject>(prefabBall); BoxCollider2D collider = tempBall.GetComponent <BoxCollider2D>(); float ballColliderHalfWidth = collider.size.x / 2; float ballColliderHalfHeight = collider.size.y / 2; spawnLocationMin = new Vector2( tempBall.transform.position.x - ballColliderHalfWidth, tempBall.transform.position.y - ballColliderHalfHeight); spawnLocationMax = new Vector2( tempBall.transform.position.x + ballColliderHalfWidth, tempBall.transform.position.y + ballColliderHalfHeight); Destroy(tempBall); // initialize and start spawn timer spawnRange = ConfigurationUtils.MaxSpawnSeconds - ConfigurationUtils.MinSpawnSeconds; spawnTimer = gameObject.AddComponent <Timer>(); spawnTimer.AddTimerFinishedListener(HandleSpawnTimerFinishedEvent); spawnTimer.Duration = GetSpawnDelay(); spawnTimer.Run(); // spwan first ball in game SpawnBall(); EventManager.AddBallsLeftEfectListener(SpawnBall); EventManager.AddDeathBallEventListener(SpawnBall); }
/// <summary> /// Use this for initialization /// </summary> void Start() { // initialize score text scoreText = GameObject.FindGameObjectWithTag("ScoreText").GetComponent <Text>(); scoreText.text = ScorePrefix + score; // initialize balls left value and text ballsLeft = ConfigurationUtils.BallsPerGame; ballsLeftText = GameObject.FindGameObjectWithTag("BallsLeftText").GetComponent <Text>(); ballsLeftText.text = BallsLeftPrefix + ballsLeft; EventManager.AddPointsAddedEffectListener(AddPoints); EventManager.AddBallsLeftEfectListener(ReduceBallsLeft); lastBallLostEvent = new LastBallLostEvent(); EventManager.AddLastBallLostEventInvoker(this); }