Exemplo n.º 1
0
    void CheckCollision()
    {
        bool  isCollision = false;
        float workNLG;

        NowLengthGlobal = NowLength * LRSize;


        for (int i = 0; i < LRSize; i++)                                                                     // przejdz prz ez wszystkie LR
        {
            currentPosition = transform.position;

            for (int j = 0; j < i; j++)
            {
                currentPosition += forwardVec * BlockLen;
            }


            workNLG = Mathf.Min(1.0f, NowLengthGlobal - i);

            if (workNLG <= 0)
            {
                break;
            }

            RaycastHit hit;

            if (Physics.Raycast(currentPosition, forwardVec, out hit, BlockLen * workNLG, shootableMask))
            {
                GameObject hitobj = hit.collider.gameObject;
                NowLength = ((BlockLen * i) + hit.distance) / MaxLength;
                HitObj.transform.position = currentPosition + forwardVec * hit.distance;
                HitObj.transform.rotation = Quaternion.AngleAxis(180.0f, transform.up) * transform.rotation;

                isCollision = true;
                break;
            }
        }
        HitObj.SetViewPat(isCollision && !BP.bEnd);
        HitObj.col = BP.BeamColor * 2;
    }
Exemplo n.º 2
0
    // Update is called once per frame
    void Update()
    {
        if (BP.bEnd)
        {
            BP.Scale *= 0.9f;
            SHP_Emitter.ShotPower = 0.0f;

            Width *= 0.9f;
            if (Width < 0.01f)
            {
                Destroy(gameObject, 2);
            }
        }
        else
        {
            SHP_Emitter.ShotPower = 1.0f;
        }

        NowLength = Mathf.Min(1.0f, NowLength + AddLength);

        Vector3 NowPos = Vector3.zero;

#pragma warning disable CS0618 // 型またはメンバーが古い形式です
        LR.SetWidth(Width * BP.Scale, Width * BP.Scale);
#pragma warning disable CS0618 // 型またはメンバーが古い形式です
        LR.SetColors(BP.BeamColor, BP.BeamColor);
#pragma warning restore CS0618 // 型またはメンバーが古い形式です
        MaxLength = BP.MaxLength;
        for (int i = LRSize - 1; i > 0; i--)
        {
            F_Vec[i] = F_Vec[i - 1];
        }
        F_Vec[0]      = transform.forward;
        F_Vec[LRSize] = F_Vec[LRSize - 1];
        float BlockLen = MaxLength / LRSize;

        for (int i = 0; i < LRSize; i++)
        {
            NowPos = transform.position;
            for (int j = 0; j < i; j++)
            {
                NowPos += F_Vec[j] * BlockLen;
            }
            LR.SetPosition(i, NowPos);
        }

        //Collision
        bool  bHitNow = false;
        float workNLG = 1.0f;
        NowLengthGlobal = NowLength * LRSize;

        if (Width >= 0.01f)
        {
            for (int i = 0; i < LRSize; i++)
            {
                workNLG = Mathf.Min(1.0f, NowLengthGlobal - i);

                NowPos = transform.position;
                for (int j = 0; j < i; j++)
                {
                    NowPos += F_Vec[j] * BlockLen;
                }


                RaycastHit hit;
                if (workNLG <= 0)
                {
                    break;
                }
                int layerMask = ~(1 << LayerMask.NameToLayer("NoBeamHit") | 1 << 2);
                if (Physics.Raycast(NowPos, F_Vec[i], out hit, BlockLen * workNLG, layerMask))
                {
                    GameObject hitobj = hit.collider.gameObject;
                    NowLength = ((BlockLen * i) + hit.distance) / MaxLength;
                    HitObj.transform.position = NowPos + F_Vec[i] * hit.distance;
                    HitObj.transform.rotation = Quaternion.AngleAxis(180.0f, transform.up) * this.transform.rotation;
                    //HitObj.transform.localScale = HitObjSize * Width * BP.Scale * 10.0f;
                    bHitNow = true;
                    break;
                }
            }
        }
        float ShotFlashScale = FlashSize * Width * 5.0f;
        Flash.GetComponent <ScaleWiggle>().DefScale = new Vector3(ShotFlashScale, ShotFlashScale, ShotFlashScale);
        HitObj.SetViewPat(bHitNow && !BP.bEnd);

        this.gameObject.GetComponent <Renderer>().material.SetFloat("_AddTex", Time.frameCount * -0.05f * BP.AnimationSpd * 10);
        this.gameObject.GetComponent <Renderer>().material.SetFloat("_BeamLength", NowLength);
        Flash.GetComponent <Renderer>().material.SetColor("_Color", BP.BeamColor * 2);
        SHP_Emitter.col = BP.BeamColor * 2;
        HitObj.col      = BP.BeamColor * 2;
    }