//---------------------------------------
    // When ball is thrown, it will create new ball
    //---------------------------------------
    private void createBall()
    {
        if (_NumShot == 3)
        {
            ball = new GameObject[3];
        }
        else
        {
            ball = new GameObject[5];
        }
        ball[0] = (GameObject)Instantiate(BallPrefb);
        BulletCollision2D bulletCo = ball[0].GetComponentInChildren <BulletCollision2D>(); bulletCo._Turn = _NumTurn;

        ball[1] = (GameObject)Instantiate(BallPrefb);
        BulletCollision2D bulletC1 = ball[1].GetComponentInChildren <BulletCollision2D>(); bulletC1._Turn = _NumTurn;

        ball[2] = (GameObject)Instantiate(BallPrefb);
        BulletCollision2D bulletC2 = ball[2].GetComponentInChildren <BulletCollision2D>(); bulletC2._Turn = _NumTurn;
        Vector3           pos      = transform.position;

        pos.z = 1;
        ball[0].transform.position = ball[1].transform.position = ball[2].transform.position = pos;
        ball[0].SetActive(false); ball[1].SetActive(false); ball[2].SetActive(false);
        if (_NumShot == 5)
        {
            ball[3] = (GameObject)Instantiate(BallPrefb);
            BulletCollision2D bulletC3 = ball[3].GetComponentInChildren <BulletCollision2D>(); bulletC3._Turn = _NumTurn;
            ball[4] = (GameObject)Instantiate(BallPrefb);
            BulletCollision2D bulletC4 = ball[4].GetComponentInChildren <BulletCollision2D>(); bulletC4._Turn = _NumTurn;
            ball[3].transform.position = ball[4].transform.position = pos;
            ball[3].SetActive(false); ball[4].SetActive(false);
        }
    }
示例#2
0
    private void InitBullet(bool isFinish)
    {
        GameObject        bullet    = (GameObject)Instantiate(_Butlet, _PosInitBullet[0].position, Quaternion.Euler(_PosInitBullet[1].position - _PosInitBullet[0].position));
        BulletCollision2D collision = bullet.GetComponentInChildren <BulletCollision2D>();

        collision._BulletFinish = isFinish;
        bullet.GetComponent <Rigidbody2D>().AddForce(GetForceFrom(_PosInitBullet[0].position, _PosInitBullet[1].position), ForceMode2D.Impulse);
    }