/// <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(HandleSpawnTimerFinished); spawnTimer.Duration = GetSpawnDelay(); spawnTimer.Run(); EventManager.AddBallDiedListener(SpawnBall); EventManager.AddBallLostListener(SpawnBall); // spawn first Ball SpawnBall(); }
/// <summary> /// Use this for initialization /// </summary> void Start() { // spawn and destroy ball to calculate // spawn location min and max GameObject tempBall = Instantiate <GameObject>(prefabStandardBall); BoxCollider2D collider = tempBall.GetComponent <BoxCollider2D>(); float ballColliderHalfWidth = collider.size.x / 2; float ballColliderHalfHeight = collider.size.y / 2; Vector2 spawnLocation = Vector2.zero; spawnLocationMin = new Vector2( spawnLocation.x - ballColliderHalfWidth, spawnLocation.y - ballColliderHalfHeight); spawnLocationMax = new Vector2( spawnLocation.x + ballColliderHalfWidth, spawnLocation.y + ballColliderHalfHeight); Destroy(tempBall); // initialize and start spawn timer spawnRange = ConfigurationUtils.MaxSpawnDelay - ConfigurationUtils.MinSpawnDelay; spawnTimer = gameObject.AddComponent <Timer>(); spawnTimer.Duration = GetSpawnDelay(); spawnTimer.Run(); spawnTimer.AddTimerFinishedListener(HandleSpawnTimerFinished); // add as listener for events EventManager.AddBallLostListener(HandleBallLostEvent); EventManager.AddBallDiedListener(HandleBallDiedEvent); }
// Start is called before the first frame update void Start() { scoreText = scoreTextGameObject.GetComponent <Text>(); leftHitsText = leftHitsTextGameObject.GetComponent <Text>(); rightHitsText = rightHitsTextGameObject.GetComponent <Text>(); // add as listener for various events EventManager.AddBallLostListener(AddPoints); EventManager.AddHitsAddedListener(AddHits); }
/// <summary> /// Use this for initialization /// </summary> void Start() { leftScore = 0; rightScore = 0; leftHits = 0; rightHits = 0; scoreText = scoreTextGameObject.GetComponent <Text>(); leftHitsText = leftHitsTextGameObject.GetComponent <Text>(); rightHitsText = rightHitsTextGameObject.GetComponent <Text>(); // add as listener for various events EventManager.AddBallLostListener(AddPoints); EventManager.AddHitsAddedListener(AddHits); EventManager.AddPlayerWonInvoker(this); }
protected override void Initialize() { gameEndedEvent = new GameEnded(); var ballsLeftGameObject = GameObject.FindGameObjectWithTag(BallsTag); ballsLeftText = ballsLeftGameObject.GetComponent <Text>(); var scoreGameObject = GameObject.FindGameObjectWithTag(ScoreTag); scoreText = scoreGameObject.GetComponent <Text>(); EventManager.AddGameEndedInvoker(this); EventManager.AddBallLostListener(OnBallLost); EventManager.AddBlockDestroyedListener(OnBlockDestroyed); GetComponent <HUD>().enabled = false; }
/// <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; // add listeners to the event manager EventManager.AddPointsAddedListener(AddPoints); EventManager.AddBallLostListener(ReduceBallsLeft); // last ball lost support lastBallLost = new LastBallLost(); EventManager.AddLastBallLostInvoker(this); }
/// <summary> /// Use this for initialization /// </summary> void Start() { // initialize score text score = 0; 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.AddPointsAddedListener(AddPoints); EventManager.AddBallLostListener(ReduceBallsLeft); lastBallLost = new LastBallLost(); EventManager.AddLastBallLostInvoker(this); // Take high score highScore = PlayerPrefs.GetInt("HighScore"); }
bool retrySpawn = true; // Pending spawn /// <summary> /// Use this for initialization /// </summary> void Start() { // Create a temp ball for measureing its size GameObject tempBall = Instantiate(StandardBall) as GameObject; // Connect the boxCollider component bc2D = tempBall.GetComponent <BoxCollider2D>(); // Get the length and height of the collider collider_length = bc2D.size.x; collider_height = bc2D.size.y; // Assgin value to the diagonal corners // divide 2 to get half length/width, divide 10 because the ball is scaled upperleft = new Vector2(-collider_length / 20, collider_height / 20); lowerright = new Vector2(collider_length / 20, -collider_height / 20); // Create and run the random timer randomTimer = gameObject.AddComponent <Timer>(); randomTimer.Duration = RandomTimerDecider(); randomTimer.Run(); // Destroy the temp ball Destroy(tempBall); // Add listeners for events EventManager.AddBallLostListener(DrawBall); EventManager.AddBallDeadListener(DrawBall); }