Exemple #1
0
    /// <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);
    }