Example #1
0
 void StateAndColorSetter(BALL_STATE bState)
 {
     //ボールの色と状態を代入する
     ballState = bState;
     //spRenderer.color = ballColor[(int)bState];
     spRenderer.color = CustomColorTheme.GetColors()[(int)bState];
 }
Example #2
0
    private void OnCollisionEnter2D(Collision2D col)
    {
        //ぶつかったボールが既に鳴ってたらやらない
        if (col.gameObject.tag == "Ball" && col.gameObject.GetComponent <Ball>().isRinging)
        {
            return;
        }
        else
        {
            //ボールの二つ分音がならないためにやってる
            isRinging = true;
            audioSource.Play();
        }

        //プレイヤー以外のぶつかりは無視
        if (col.gameObject.tag != "Player")
        {
            return;
        }

        //OnCollisionEnter2Dの順番よくわからんからこれで色保持してる
        prevBallState = ballState;
        //ボールの色によって運命が決まる
        switch (ballState)
        {
        case BALL_STATE.GREEN:
            Score.ScoreAdder();
            //GameObject newBall = Instantiate(ball);
            Ball newBall = BallFactory.GetInstance();     // by tada
            if (newBall != null)
            {
                newBall.transform.position = this.transform.position;
                newBall.GetComponent <Rigidbody2D>().velocity =
                    Quaternion.Euler(0, 0, Random.Range(-30f, 30f)) * rigidbody2d.velocity.normalized * 10f;
                newBall.PlayEffect();
            }
            StateAndColorSetter(BALL_STATE.BLUE);
            // 2つの玉からエフェクトを出す
            PlayEffect();
            break;

        case BALL_STATE.RED:

            // 死亡エフェクトを出す
            EffectFactory.Play(eEffectType.Burst, transform.position, (int)BALL_STATE.RED);
            Score.GameOver();
            // ボールを消す
            gameObject.SetActive(false);
            break;
        }
    }
Example #3
0
    void onTap()
    {
        if (Input.GetMouseButtonDown(0))
        {
            if (!_isStarted)
            {
                _isStarted          = true;
                _rigidBody.velocity = new Vector3(_speed, 0, 0);
            }
            switch (_ballState)
            {
            case BALL_STATE.LEFT:
                _ballState          = BALL_STATE.RIGHT;
                _rigidBody.velocity = new Vector3(_speed, 0, 0);
                break;

            case BALL_STATE.RIGHT:
                _ballState          = BALL_STATE.LEFT;
                _rigidBody.velocity = new Vector3(0, 0, _speed);
                break;
            }
        }
    }