// 원형 판정 탄막 발사 함수 (스프라이트 회전 X)
    public void CircleBulletFire
        (GameObject obj, int bulletNumber, int bulletLayer, Vector2 bulletFirePosition, Vector3 bulletScale,
        Transform bulletParent, float circleColliderRadius, float circleColliderOffsetX, float circleColliderOffsetY, float spriteAlpha, int spriteNumber, bool isAnimation, int animatorNumber,
        BulletType bulletType, GameObject targetObject, BulletSpeedState bulletSpeedState, float bulletMoveSpeed,
        float bulletAccelerationMoveSpeed, float bulletAccelerationMoveSpeedMax, float bulletDecelerationMoveSpeed, float bulletDecelerationMoveSpeedMin, bool bulletMoveSpeedLoopBool, bool bulletMoveSpeedLoopOnceBool,
        BulletRotateState bulletRotateState, float bulletRotateSpeed, float bulletRotateLimit,
        int bulletDestinationType, Vector2 targetPosition, float addRotateAngle, int customPatternNumber = 0, bool isSpriteRotate = false,
        float spriteRotateSpeed = 0.0f, bool isGravity = false, float velocity = 0.0f, float gravityScale = 0.0f, bool isLookAt = false)
    {
        obj.SetActive(true);
        // ClearChild(obj);
        BulletState      bulletState      = obj.GetComponent <BulletState>();
        BulletMove       bulletMove       = obj.GetComponent <BulletMove>();
        ObjectRotate     objectRotate     = obj.GetComponent <ObjectRotate>();
        CircleCollider2D circleCollider2D = obj.GetComponent <CircleCollider2D>();
        SpriteRenderer   spriteRenderer   = obj.GetComponent <SpriteRenderer>();
        Animator         animator         = obj.GetComponent <Animator>();
        Rigidbody2D      rigidbody2D      = obj.GetComponent <Rigidbody2D>();

        bulletState.bulletObject = obj;
        bulletState.bulletNumber = bulletNumber;
        obj.gameObject.layer     = bulletLayer;
        obj.transform.position   = bulletFirePosition;
        obj.transform.localScale = bulletScale;
        obj.transform.SetParent(bulletParent);
        circleCollider2D.radius = circleColliderRadius;
        circleCollider2D.offset = new Vector2(circleColliderOffsetX, circleColliderOffsetY);
        spriteRenderer.color    = new Color(1.0f, 1.0f, 1.0f, spriteAlpha);
        spriteRenderer.sprite   = gameManager.bulletSprite[spriteNumber];
        if (isAnimation.Equals(true))
        {
            animator.runtimeAnimatorController = gameManager.bulletAnimatorController[animatorNumber];
        }
        else
        {
            animator.runtimeAnimatorController = null;
        }
        bulletState.bulletType                     = bulletType;
        bulletState.targetObject                   = targetObject;
        bulletState.isGrazed                       = false;
        bulletState.bulletSpeedState               = bulletSpeedState;
        bulletState.bulletMoveSpeed                = bulletMoveSpeed;
        bulletState.bulletAccelerationMoveSpeed    = bulletAccelerationMoveSpeed;
        bulletState.bulletAccelerationMoveSpeedMax = bulletAccelerationMoveSpeedMax;
        bulletState.bulletDecelerationMoveSpeed    = bulletDecelerationMoveSpeed;
        bulletState.bulletDecelerationMoveSpeedMin = bulletDecelerationMoveSpeedMin;
        bulletState.bulletMoveSpeedLoopBool        = bulletMoveSpeedLoopBool;
        bulletState.bulletMoveSpeedLoopOnceBool    = bulletMoveSpeedLoopOnceBool;
        bulletState.bulletRotateState              = bulletRotateState;
        bulletState.bulletRotateSpeed              = bulletRotateSpeed;
        bulletState.bulletRotateLimit              = bulletRotateLimit;
        switch (bulletDestinationType)
        {
        case 1:
            bulletState.bulletDestination = bulletState.GetBulletDestination(targetPosition);
            break;

        case 2:
            bulletState.bulletDestination = bulletState.GetRandomAimedBulletDestination();
            break;

        case 3:
            bulletState.bulletDestination = bulletState.GetAimedBulletDestination();
            break;

        default:
            bulletState.bulletDestination = bulletState.GetBulletDestination(new Vector2(obj.transform.position.x, obj.transform.position.y - 5.0f));
            break;
        }
        float angle = Mathf.Atan2(bulletState.bulletDestination.y, bulletState.bulletDestination.x) * Mathf.Rad2Deg;

        bulletMove.ChangeRotateAngle(angle - 90.0f + addRotateAngle);

        if (isSpriteRotate.Equals(true))
        {
            objectRotate.rotateSpeed = spriteRotateSpeed;
        }
        if (isGravity.Equals(true))
        {
            // rigidbody2D.AddForce(bullet.transform.position * velocity);
            rigidbody2D.AddForce(bulletState.bulletDestination.normalized * velocity);
            rigidbody2D.gravityScale = gravityScale;
            bulletState.isLookAt     = isLookAt;
        }

        // 커스텀 패턴 스크립트 넣기 (제작하는 대로 넣을 것)
        switch (customPatternNumber)
        {
        case 1:
            obj.AddComponent <BulletReaiming>();
            break;

        default:
            break;
        }
    }
Ejemplo n.º 2
0
    private IEnumerator Reaiming()
    {
        if (isSpeedDown.Equals(true))
        {
            while (true)
            {
                yield return(null);

                if (bulletState.bulletMoveSpeed <= 0.0f)
                {
                    // 효과음 재생
                    SoundManager.instance.PlaySE(soundNumber);

                    if (isPlayerAimed.Equals(true))
                    {
                        targetPosition = playerPosition.position;
                    }
                    else if (isRandomAimed.Equals(true))
                    {
                        targetPosition = new Vector3(Random.Range(-5.0f, 5.0f), Random.Range(-5.0f, 5.0f), 0.0f);
                    }
                    bulletState.bulletSpeedState  = bulletSpeedState;
                    bulletState.bulletRotateState = bulletRotateState;
                    bulletState.bulletMoveSpeed   = bulletMoveSpeed;
                    bulletState.bulletRotateSpeed = bulletRotateSpeed;
                    bulletState.bulletRotateLimit = bulletRotateLimit;
                    bulletState.bulletDestination = bulletState.GetBulletDestination(targetPosition);
                    float angle = Mathf.Atan2(bulletState.bulletDestination.y, bulletState.bulletDestination.x) * Mathf.Rad2Deg;
                    bulletMove.ChangeRotateAngle(angle - 90.0f);
                    changeCount++;
                    break;
                }
            }

            if (changeCount < repeatCount)
            {
                StartCoroutine(Reaiming());
            }
        }
        else if (isTimer.Equals(true))
        {
            yield return(new WaitForSeconds(waitTime));

            if (isPlayerAimed.Equals(true))
            {
                targetPosition = playerPosition.position;
            }
            else if (isRandomAimed.Equals(true))
            {
                targetPosition = new Vector3(Random.Range(-5.0f, 5.0f), Random.Range(-5.0f, 5.0f), 0.0f);
            }
            bulletState.bulletSpeedState  = bulletSpeedState;
            bulletState.bulletRotateState = bulletRotateState;
            bulletState.bulletMoveSpeed   = bulletMoveSpeed;
            bulletState.bulletRotateSpeed = bulletRotateSpeed;
            bulletState.bulletRotateLimit = bulletRotateLimit;
            bulletState.bulletDestination = bulletState.GetBulletDestination(targetPosition);
            float angle = Mathf.Atan2(bulletState.bulletDestination.y, bulletState.bulletDestination.x) * Mathf.Rad2Deg;
            bulletMove.ChangeRotateAngle(angle - 90.0f);
            changeCount++;

            if (changeCount < repeatCount)
            {
                StartCoroutine(Reaiming());
            }
        }
    }
Ejemplo n.º 3
0
    private void Update()
    {
        bulletState.bulletRotateTime += Time.deltaTime;

        // 탄속 변경 (가속 탄막)
        if (bulletState.bulletSpeedState.Equals(BulletSpeedState.BULLETSPEEDSTATE_ACCELERATING))
        {
            bulletState.bulletMoveSpeed += bulletState.bulletAccelerationMoveSpeed;
            if (!bulletState.bulletAccelerationMoveSpeedMax.Equals(0.0f))
            {
                if (bulletState.bulletMoveSpeed >= bulletState.bulletAccelerationMoveSpeedMax)
                {
                    bulletState.bulletMoveSpeed = bulletState.bulletAccelerationMoveSpeedMax;
                }
            }
        }
        // 탄속 변경 (감속 탄막)
        else if (bulletState.bulletSpeedState.Equals(BulletSpeedState.BULLETSPEEDSTATE_DECELERATING))
        {
            bulletState.bulletMoveSpeed -= bulletState.bulletDecelerationMoveSpeed;
            if (!bulletState.bulletDecelerationMoveSpeedMin.Equals(0.0f))
            {
                if (bulletState.bulletMoveSpeed <= bulletState.bulletDecelerationMoveSpeedMin)
                {
                    bulletState.bulletMoveSpeed = bulletState.bulletDecelerationMoveSpeedMin;
                }
            }
            else
            {
                if (bulletState.bulletMoveSpeed <= 0.0f)
                {
                    bulletState.bulletMoveSpeed = 0.0f;
                }
            }
        }
        // 탄속 변경 (가속, 감속 반복 탄막)
        else if (bulletState.bulletSpeedState.Equals(BulletSpeedState.BULLETSPEEDSTATE_LOOP))
        {
            if (bulletState.bulletMoveSpeedLoopBool.Equals(true))
            {
                bulletState.bulletMoveSpeed += bulletState.bulletAccelerationMoveSpeed;
                if (bulletState.bulletMoveSpeed >= bulletState.bulletAccelerationMoveSpeedMax)
                {
                    bulletState.bulletMoveSpeedLoopBool = false;
                }
            }
            else
            {
                bulletState.bulletMoveSpeed -= bulletState.bulletDecelerationMoveSpeed;
                if (bulletState.bulletMoveSpeed <= bulletState.bulletDecelerationMoveSpeedMin)
                {
                    bulletState.bulletMoveSpeedLoopBool = true;
                }
            }
        }
        // 탄속 변경 (가속, 감속 1회 반복 탄막)
        else if (bulletState.bulletSpeedState.Equals(BulletSpeedState.BULLETSPEEDSTATE_LOOPONCE))
        {
            if (bulletState.bulletMoveSpeedLoopBool.Equals(true))
            {
                bulletState.bulletMoveSpeed += bulletState.bulletAccelerationMoveSpeed;
                if (bulletState.bulletMoveSpeed >= bulletState.bulletAccelerationMoveSpeedMax)
                {
                    bulletState.bulletMoveSpeedLoopBool = false;
                    bulletState.bulletSpeedState        = BulletSpeedState.BULLETSPEEDSTATE_DECELERATING;
                }
            }
            else
            {
                bulletState.bulletMoveSpeed -= bulletState.bulletDecelerationMoveSpeed;
                if (bulletState.bulletMoveSpeed <= bulletState.bulletDecelerationMoveSpeedMin)
                {
                    bulletState.bulletMoveSpeedLoopBool = true;
                    bulletState.bulletSpeedState        = BulletSpeedState.BULLETSPEEDSTATE_ACCELERATING;
                }
            }
        }

        // 탄도 변경 (지속 증감)
        if (!bulletState.bulletRotateSpeed.Equals(0.0f))
        {
            if (bulletState.bulletRotateState.Equals(BulletRotateState.BULLETROTATESTATE_NORMAL))
            {
                transform.Rotate(Vector3.forward * bulletState.bulletRotateSpeed * Time.deltaTime);
            }
            else if (bulletState.bulletRotateState.Equals(BulletRotateState.BULLETROTATESTATE_LIMIT))
            {
                transform.Rotate(Vector3.forward * bulletState.bulletRotateSpeed * Time.deltaTime);
                if (bulletState.bulletRotateTime >= bulletState.bulletRotateLimit)
                {
                    bulletState.bulletRotateSpeed = 0.0f;
                }
            }
            else if (bulletState.bulletRotateState.Equals(BulletRotateState.BULLETROTATESTATE_ROTATEAROUND))
            {
                RotateAround(bulletState.bulletDestination);
            }
        }
        // 탄도 변경 (지속적으로 대상을 향해 바라보기)
        else if (bulletState.bulletRotateState.Equals(BulletRotateState.BULLETROTATESTATE_LOOKAT))
        {
            bulletState.bulletDestination = bulletState.GetBulletDestination(bulletState.targetObject.transform.position);
            float angle = Mathf.Atan2(bulletState.bulletDestination.y, bulletState.bulletDestination.x) * Mathf.Rad2Deg;
            if (bulletState.bulletType.Equals(BulletType.BULLETTYPE_LASER_MOVE))
            {
                ChangeRotateAngle(angle - 180.0f);
            }
            else
            {
                ChangeRotateAngle(angle - 90.0f);
            }
        }

        // 탄막 이동
        if (bulletState.bulletType.Equals(BulletType.BULLETTYPE_NORMAL))
        {
            transform.Translate(Vector2.up * bulletState.bulletMoveSpeed * Time.deltaTime);
            // transform.localPosition = Vector2.MoveTowards(transform.position, GetBulletDestination(targetPosition), bulletMoveSpeed * Time.deltaTime);
        }
        else
        {
            transform.Translate(Vector2.right * bulletState.bulletMoveSpeed * Time.deltaTime);
            // transform.localPosition = Vector2.MoveTowards(transform.position, GetBulletDestination(targetPosition), bulletMoveSpeed * Time.deltaTime);
        }
    }