Esempio n. 1
0
 void Update()
 {
     //if (Laser.material.HasProperty("_SpeedMainTexUVNoiseZW")) Laser.material.SetVector("_SpeedMainTexUVNoiseZW", LaserSpeed);
     //SetVector("_TilingMainTexUVNoiseZW", Length); - old code, _TilingMainTexUVNoiseZW no more exist
     Laser.material.SetTextureScale("_MainTex", new Vector2(Length[0], Length[1]));
     Laser.material.SetTextureScale("_Noise", new Vector2(Length[2], Length[3]));
     //To set LineRender position
     if (Laser != null && UpdateSaver == false)
     {
         Laser.SetPosition(0, transform.position);
         RaycastHit hit;                                                                                             //DELETE THIS IF YOU WANT USE LASERS IN 2D
         //ADD THIS IF YOU WANNT TO USE LASERS IN 2D: RaycastHit2D hit = Physics2D.Raycast(transform.position, transform.forward, MaxLength);
         if (Physics.Raycast(transform.position, transform.TransformDirection(Vector3.forward), out hit, MaxLength)) //CHANGE THIS IF YOU WANT TO USE LASERRS IN 2D: if (hit.collider != null)
         {
             //End laser position if collides with object
             Laser.SetPosition(1, hit.point);
             HitEffect.transform.position = hit.point + hit.normal * HitOffset;
             //Hit effect zero rotation
             HitEffect.transform.rotation = Quaternion.identity;
             foreach (var AllPs in Effects)
             {
                 if (!AllPs.isPlaying)
                 {
                     AllPs.Play();
                 }
             }
             //Texture tiling
             Length[0] = MainTextureLength * (Vector3.Distance(transform.position, hit.point));
             Length[2] = NoiseTextureLength * (Vector3.Distance(transform.position, hit.point));
             //Texture speed balancer {DISABLED AFTER UPDATE}
             //LaserSpeed[0] = (LaserStartSpeed[0] * 4) / (Vector3.Distance(transform.position, hit.point));
             //LaserSpeed[2] = (LaserStartSpeed[2] * 4) / (Vector3.Distance(transform.position, hit.point));
         }
         else
         {
             //End laser position if doesn't collide with object
             var EndPos = transform.position + transform.forward * MaxLength;
             Laser.SetPosition(1, EndPos);
             HitEffect.transform.position = EndPos;
             foreach (var AllPs in Hit)
             {
                 if (AllPs.isPlaying)
                 {
                     AllPs.Stop();
                 }
             }
             //Texture tiling
             Length[0] = MainTextureLength * (Vector3.Distance(transform.position, EndPos));
             Length[2] = NoiseTextureLength * (Vector3.Distance(transform.position, EndPos));
             //LaserSpeed[0] = (LaserStartSpeed[0] * 4) / (Vector3.Distance(transform.position, EndPos)); {DISABLED AFTER UPDATE}
             //LaserSpeed[2] = (LaserStartSpeed[2] * 4) / (Vector3.Distance(transform.position, EndPos)); {DISABLED AFTER UPDATE}
         }
         //Insurance against the appearance of a laser in the center of coordinates!
         if (Laser.enabled == false && LaserSaver == false)
         {
             LaserSaver    = true;
             Laser.enabled = true;
         }
     }
 }
Esempio n. 2
0
    public void ShootLaser()
    {
        //Laser.SetPosition(1, MachineGun.crosshair.transform.position);

        HitEffect.transform.position = MachineGun.crosshair.transform.position;
        HitEffect.transform.rotation = Quaternion.identity;

        foreach (var AllPs in Effects)
        {
            if (!AllPs.isPlaying)
            {
                AllPs.Play();
            }
        }


        //Length[0] = MainTextureLength * (Vector3.Distance(transform.position, MachineGun.crosshair.transform.position));
        //Length[2] = NoiseTextureLength * (Vector3.Distance(transform.position, MachineGun.crosshair.transform.position));


        //Insurance against the appearance of a laser in the center of coordinates!
        if (/*Laser.enabled == false && */ LaserSaver == false)
        {
            LaserSaver = true;
            //Laser.enabled = true;
        }
    }
Esempio n. 3
0
    void Update()
    {
        if (target == null)
        {
            return;
        }

        Laser.material.SetTextureScale("_MainTex", new Vector2(Length[0], Length[1]));
        Laser.material.SetTextureScale("_Noise", new Vector2(Length[2], Length[3]));

        var targetPosition = target.position;
        var targetNormal   = (target.position - transform.position).normalized;

        //To set LineRender position
        if (Laser != null && UpdateSaver == false)
        {
            Laser.SetPosition(0, transform.position);
            Laser.SetPosition(1, targetPosition);

            HitEffect.transform.position = targetPosition + targetNormal * HitOffset;
            if (useLaserRotation)
            {
                HitEffect.transform.rotation = transform.rotation;
            }
            else
            {
                HitEffect.transform.LookAt(targetPosition + targetNormal);
            }

            foreach (var AllPs in Effects)
            {
                if (!AllPs.isPlaying)
                {
                    AllPs.Play();
                }
            }
            //Texture tiling
            Length[0] = MainTextureLength * (Vector3.Distance(transform.position, targetPosition));
            Length[2] = NoiseTextureLength * (Vector3.Distance(transform.position, targetPosition));

            //Insurance against the appearance of a laser in the center of coordinates!
            if (Laser.enabled == false && LaserSaver == false)
            {
                LaserSaver    = true;
                Laser.enabled = true;
            }
        }
    }