Ejemplo n.º 1
0
    /// <summary>
    /// 탄환 생성 코루틴입니다.
    /// </summary>
    /// <param name="index">탄환 인덱스입니다.</param>
    /// <returns></returns>
    IEnumerator CreateBulletCoroutine(int index)
    {
        // 사용할 변수를 선언합니다.
        Transform shotPosition = GetShotPosition();
        bool      toLeft       = (Sliding ? FacingRight : !FacingRight);


        // 탄환 발사 효과에 대해 먼저 생성하고 처리합니다.
        GameObject fireEffect = CloneObject(effects[7 + index], shotPosition);

        if (index == 2)
        {
            if (IsAnimationPlaying("Idle"))
            {
                fireEffect.transform.position = transform.position;
            }
        }
        Vector3 effectScale = fireEffect.transform.localScale;

        effectScale.x *= (toLeft ? -1 : 1);
        fireEffect.transform.localScale = effectScale;
        fireEffect.transform.parent     = shotPosition.transform;

        // 버스터 컴포넌트를 발사체에 붙입니다.
        GameObject _bullet = CloneObject(_bullets[index], shotPosition);

        // 2단계 차지샷이라면 잠시 대기합니다.
        if (index == 2)
        {
            _bullet.GetComponent <SpriteRenderer>().color = Color.clear;
            yield return(new WaitForSeconds(0.15f));
        }

        //
        if (_bullet != null)
        {
            _bullet.GetComponent <SpriteRenderer>().color = Color.white;
            _bullet.transform.position = shotPosition.position;

            // 위치를 조정합니다.
            Vector3 bulletScale = _bullet.transform.localScale;
            bulletScale.x *= (toLeft ? -1 : 1);
            _bullet.transform.localScale = bulletScale;
            _bullet.GetComponent <Rigidbody2D>().velocity
                = (toLeft ? Vector3.left : Vector3.right) * _shotSpeed;

            // 탄환 속성을 업데이트 합니다.
            XBusterScript buster = _bullet.GetComponent <XBusterScript>();
            buster.MainCamera = Camera.main; // stageManager.MainCamera;
        }

        yield break;
    }
Ejemplo n.º 2
0
    /// <summary>
    /// 탄환을 생성합니다.
    /// </summary>
    /// <param name="index">탄환 타입을 표현하는 인덱스입니다.</param>
    void CreateBullet(int index)
    {
        // 사용할 변수를 선언합니다.
        Transform  shotPosition = GetShotPosition();
        GameObject _bullet      = CloneObject(_bullets[index], shotPosition);
        Vector3    bulletScale  = _bullet.transform.localScale;
        bool       toLeft       = (Sliding ? FacingRight : !FacingRight);


        GameObject fireEffect = CloneObject(effects[7 + index], shotPosition);

        if (index == 2)
        {
            fireEffect.transform.position = transform.position;
        }

        Vector3 effectScale = fireEffect.transform.localScale;


        // 위치를 조정합니다.
        bulletScale.x *= (toLeft ? -1 : 1);
        _bullet.transform.localScale = bulletScale;
        _bullet.GetComponent <Rigidbody2D>().velocity
            = (toLeft ? Vector3.left : Vector3.right) * _shotSpeed;


        // 발사 효과를 생성합니다.
        effectScale.x *= (toLeft ? -1 : 1);
        fireEffect.transform.localScale = effectScale;
        fireEffect.transform.parent     = shotPosition.transform;


        // 버스터 컴포넌트를 발사체에 붙입니다.
        XBusterScript buster = _bullet.GetComponent <XBusterScript>();

        buster.MainCamera = Camera.main; // _stageManager.MainCamera;
    }