コード例 #1
0
    [HideInInspector] public bool isEffectOutput;                         // 반사 시 이펙트 출력 여부

    // 탄막 정보 초기화
    public void InitBulletState()
    {
        bulletType         = BulletType.BULLETTYPE_NONE;
        bulletReflectState = BulletReflectState.BULLETREFLECTSTATE_NONE;
        bulletSpeedState   = BulletSpeedState.BULLETSPEEDSTATE_NONE;
        bulletRotateState  = BulletRotateState.BULLETROTATESTATE_NONE;

        bulletPosition    = new Vector2(0.0f, 0.0f);
        targetPosition    = new Vector2(0.0f, 0.0f);
        bulletDestination = new Vector2(0.0f, 0.0f);

        bulletNumber = 0;
        distance     = 0.0f;
        isGrazed     = false;

        bulletMoveSpeed                = 0.0f;
        bulletAccelerationMoveSpeed    = 0.0f;
        bulletAccelerationMoveSpeedMax = 0.0f;
        bulletDecelerationMoveSpeed    = 0.0f;
        bulletDecelerationMoveSpeedMin = 0.0f;
        bulletMoveSpeedLoopBool        = false;
        bulletMoveSpeedLoopOnceBool    = false;

        bulletRotateTime  = 0.0f;
        bulletRotateLimit = 0.0f;
        bulletRotateSpeed = 0.0f;
        isLookAt          = false;

        reflectCount   = 0;
        reflectLimit   = 0;
        isSpriteChange = false;
        isEffectOutput = false;
    }
コード例 #2
0
    private void BulletReaimingSetting(GameObject bullet, int repeatCount, int soundNumber, float waitTime,
                                       BulletSpeedState bulletSpeedState, float bulletMoveSpeed, BulletRotateState bulletRotateState, float bulletRotateSpeed, float bulletRotateLimit,
                                       bool isPlayerAimed, bool isRandomAimed, bool isSpeedDown, bool isTimer)
    {
        BulletReaiming bulletReaiming = bullet.GetComponent <BulletReaiming>();

        bulletReaiming.repeatCount       = repeatCount;
        bulletReaiming.soundNumber       = soundNumber;
        bulletReaiming.waitTime          = waitTime;
        bulletReaiming.bulletSpeedState  = bulletSpeedState;
        bulletReaiming.bulletMoveSpeed   = bulletMoveSpeed;
        bulletReaiming.bulletRotateState = bulletRotateState;
        bulletReaiming.bulletRotateSpeed = bulletRotateSpeed;
        bulletReaiming.bulletRotateLimit = bulletRotateLimit;
        bulletReaiming.isPlayerAimed     = isPlayerAimed;
        bulletReaiming.isRandomAimed     = isRandomAimed;
        bulletReaiming.isSpeedDown       = isSpeedDown;
        bulletReaiming.isTimer           = isTimer;
    }
コード例 #3
0
    void Update()
    {
        bulletRotateTime += Time.deltaTime;

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

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

        // 탄막 이동
        if (initializeBullet.bulletType.Equals(BulletType.BULLETTYPE_NORMAL))
        {
            transform.Translate(Vector2.up * bulletMoveSpeed * Time.deltaTime);
        }
        else
        {
            transform.Translate(Vector2.right * bulletMoveSpeed * Time.deltaTime);
        }

        // 탄막 그레이즈
        if (isGrazing.Equals(true))
        {
            grazeDelay += Time.deltaTime;
            if (grazeDelay >= 0.1f)
            {
                playerDatabase.grazeCount++;
                grazeDelay = 0.0f;
            }
        }
        else
        {
            grazeDelay = 0.0f;
        }

        // 콜라이더 활성화
        if (!initializeBullet.bulletType.Equals(BulletType.BULLETTYPE_LASER_HOLD) && Vector2.Distance(transform.position, playerObject.transform.position) <= 0.5f)
        {
            if (!circleCollider2D.Equals(null))
            {
                circleCollider2D.enabled = true;
            }
            else if (!capsuleCollider2D.Equals(null))
            {
                capsuleCollider2D.enabled = true;
            }
            else if (!boxCollider2D.Equals(null))
            {
                boxCollider2D.enabled = true;
            }
        }
        else
        {
            Vector3 targetScreenPos = Camera.main.WorldToScreenPoint(gameObject.transform.position);
            if (((targetScreenPos.x > Screen.width || targetScreenPos.x < 0.0f) || (targetScreenPos.y > Screen.height || targetScreenPos.y < 0.0f)) ||
                (gameManager.isCleared.Equals(true)))
            {
                if (!circleCollider2D.Equals(null))
                {
                    circleCollider2D.enabled = true;
                }
                else if (!capsuleCollider2D.Equals(null))
                {
                    capsuleCollider2D.enabled = true;
                }
                else if (!boxCollider2D.Equals(null))
                {
                    boxCollider2D.enabled = true;
                }
            }
        }
    }
コード例 #4
0
    // 원형 판정 탄막 발사 함수 (스프라이트 회전 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;
        }
    }