Пример #1
0
    void Attacked(CS_Bullet _bullet)
    {
        isKnockBack     = true;
        knockbackLength = 0.8f;

        knockbackDir = new Vector2(_bullet.GetVelocity().x, _bullet.GetVelocity().y).normalized;
        posToReach   = knockbackDir * knockbackLength + new Vector2(transform.position.x, transform.position.y);

        // posToReach가 활동 영역을 넘지 않도록 보정한다.
        if (mapBoundary.bounds.min.x > posToReach.x)
        {
            posToReach.x = mapBoundary.bounds.min.x;
        }
        else if (mapBoundary.bounds.max.x < posToReach.x)
        {
            posToReach.x = mapBoundary.bounds.max.x;
        }

        if (mapBoundary.bounds.min.y > posToReach.y)
        {
            posToReach.y = mapBoundary.bounds.min.y;
        }
        else if (mapBoundary.bounds.max.y < posToReach.y)
        {
            posToReach.y = mapBoundary.bounds.max.y;
        }

        _bullet.soundAttack.Play();
    }
Пример #2
0
    public void SetInitInfo(Vector2 _dir, float _velocity, float _effectiveRange, E_BulletType _bulletType = E_BulletType.Independent, int _spreadNum = 1, float _spreadDegree = 0.0f, string _bulletName = "Bullet")
    {
        isActivated    = true;
        bulletType     = _bulletType;
        effectiveRange = _effectiveRange;
        dir            = _dir;
        velocity       = _velocity;
        spreadNum      = _spreadNum;
        spreadDegree   = _spreadDegree;

        if (bulletType == E_BulletType.Group)
        {
            bulletPrefab = Resources.Load("Prefabs/" + _bulletName) as GameObject;

            for (int i = 0; i < spreadNum; i++)
            {
                Quaternion rot       = Quaternion.Euler(0.0f, 0.0f, Random.Range(-spreadDegree / 2.0f, spreadDegree / 2.0f)); // 회전각
                Vector2    rottedDir = rot * dir;
                GameObject newObject = Instantiate(bulletPrefab);
                CS_Bullet  bullet    = newObject.GetComponent <CS_Bullet>();
                bullet.transform.position = transform.position;
                bullet.SetInitInfo(rottedDir, velocity, effectiveRange);
            }

            DestroyObject(this.gameObject);
        }
    }
Пример #3
0
    private void OnCollisionEnter2D(Collision2D collision)
    {
        if (collision.gameObject.tag == "Bullet")
        {
            CS_Bullet bullet = collision.gameObject.GetComponent <CS_Bullet>();
            Attacked(bullet);

            collision.gameObject.GetComponent <SpriteRenderer>().enabled   = false;
            collision.gameObject.GetComponent <CircleCollider2D>().enabled = false;

            DestroyObject(collision.gameObject, 3f);
        }
    }
Пример #4
0
    public override void AxisAction()
    {
        // 장전 요청이 들어오면 장전을 수행함.
        if (!isReloadCompleted)
        {
            elapsedTime += Time.deltaTime;

            if (elapsedTime >= reloadTime)
            {
                curBulletNum      = maxBulletNum;
                isReloadCompleted = true;
                // 장전이 완료되면 바로 쏠 수 있도록 함.
                remainingTime = 0.0f;
                elapsedTime   = delay - remainingTime;
            }
        }

        if (CS_Managers.Instance.InputManager.IsOutsideOfReloadRadius())
        {
            //elapsedTime = delay - remainingTime;
            if (isReloadCompleted)
            {
                elapsedTime += Time.deltaTime;

                if (elapsedTime >= delay)
                {
                    if (curBulletNum > 0)
                    {
                        curBulletNum--;
                        soundBang.Play();
                        GameObject newObject = Instantiate(bulletPrefab);
                        CS_Bullet  bullet    = newObject.GetComponent <CS_Bullet>();
                        bullet.transform.position = GetPosition();
                        //bullet.SetInitInfo(currentDir, 25.0f, 4.0f, E_BulletType.Group, 8, 20.0f);
                        bullet.SetInitInfo(currentDir, 25.0f, 100.0f);
                        ReboundAgainstShot();
                    }
                    elapsedTime = 0.0f;
                }
            }
        }
        else
        {
            remainingTime = Mathf.Clamp(remainingTime - Time.deltaTime, 0.0f, delay);
        }

        // 반동에 대한 회복
        float translate = (springArmLength - imagePosL.localPosition.x) * 0.4f;

        imagePosL.localPosition = new Vector3(imagePosL.localPosition.x + translate, 0.0f, 0.0f);
    }