Exemple #1
0
 public void DisablePrepare()
 {
     transform.parent = null;
     dissovleTimer    = 0;
     startDissovle    = true;
     UpdateSaver      = true;
     if (Flash != null && Hit != null)
     {
         foreach (var AllHits in Hit)
         {
             if (AllHits.isPlaying)
             {
                 AllHits.Stop();
             }
         }
         foreach (var AllFlashes in Flash)
         {
             if (AllFlashes.isPlaying)
             {
                 AllFlashes.Stop();
             }
         }
     }
 }
Exemple #2
0
    void Update()
    {
        if (laserPS != null && UpdateSaver == false)
        {
            //Set start laser point
            laserMat.SetVector("_StartPoint", transform.position);
            //Set end laser point
            RaycastHit hit;
            if (Physics.Raycast(transform.position, transform.TransformDirection(Vector3.forward), out hit, MaxLength))
            {
                particleCount = Mathf.RoundToInt(hit.distance / (2 * laserScale));
                if (particleCount < hit.distance / (2 * laserScale))
                {
                    particleCount += 1;
                }
                particlesPositions = new Vector3[particleCount];
                AddParticles();

                laserMat.SetFloat("_Distance", hit.distance);
                laserMat.SetVector("_EndPoint", hit.point);
                if (Hit != null)
                {
                    HitEffect.transform.position = hit.point + hit.normal * HitOffset;
                    HitEffect.transform.LookAt(hit.point);
                    foreach (var AllHits in Hit)
                    {
                        if (!AllHits.isPlaying)
                        {
                            AllHits.Play();
                        }
                    }
                    foreach (var AllFlashes in Flash)
                    {
                        if (!AllFlashes.isPlaying)
                        {
                            AllFlashes.Play();
                        }
                    }
                }
            }
            else
            {
                //End laser position if doesn't collide with object
                var EndPos   = transform.position + transform.forward * MaxLength;
                var distance = Vector3.Distance(EndPos, transform.position);
                particleCount = Mathf.RoundToInt(distance / (2 * laserScale));
                if (particleCount < distance / (2 * laserScale))
                {
                    particleCount += 1;
                }
                particlesPositions = new Vector3[particleCount];
                AddParticles();

                laserMat.SetFloat("_Distance", distance);
                laserMat.SetVector("_EndPoint", EndPos);
                if (Hit != null)
                {
                    HitEffect.transform.position = EndPos;
                    foreach (var AllPs in Hit)
                    {
                        if (AllPs.isPlaying)
                        {
                            AllPs.Stop();
                        }
                    }
                }
            }
        }

        if (startDissovle)
        {
            dissovleTimer += Time.deltaTime;
            laserMat.SetFloat("_Dissolve", dissovleTimer * 5);
        }
    }