Exemplo n.º 1
0
        private void ShootRay(int index, Quaternion direction)
        {
            // Shoots the ray.
            RaycastHit hitInfo;

            if (Physics.Raycast(bulletSpawn.position, direction * Vector3.forward, out hitInfo, 1000.0f, firingLayerMask))
            {
                // List of conductors activated by this shot.
                List <ConductorBox> conductorsActivated = null;

                // Tries to get an entity component from the object.
                EntityBase entity = null;
                if (hitInfo.rigidbody) // Searches for the EntityBase on the object with the Rigidbody.
                {
                    entity = hitInfo.rigidbody.GetComponent <EntityBase>();
                }
                if (entity != null)
                {
                    // Spawn the blood splatter effect if avaliable and hit a player or enemy.
                    if (entity.bloodEffect != null)
                    {
                        Instantiate(entity.bloodEffect, hitInfo.point, Quaternion.LookRotation(hitInfo.normal));
                    }

                    if (entity.conductorBox != null)
                    {
                        conductorsActivated = entity.conductorBox.Electrify(chainDamage);
                    }

                    // Does the damage.
                    entity.Damage(baseDamage, 0);
                }

                // Check if the object collided have an conductor box and doesnt have any entity attached to.
                ConductorBox conductorBox = hitInfo.collider.GetComponent <ConductorBox>();
                if (hitInfo.collider.isTrigger && !(conductorBox == null || conductorBox.entity != null))
                {
                    // If those requisites are satisfied, then this object must be an conductor (water). So, Electrify!
                    conductorsActivated = conductorBox.Electrify(chainDamage);
                }

                // Does the visual effect.
                lineRenderers[index].positionCount = 2;
                lineRenderers[index].SetPosition(0, bulletSpawn.transform.position);
                lineRenderers[index].SetPosition(1, hitInfo.point);

                StartCoroutine(TimedVisualEffect(index, conductorsActivated));
            }
            else   // If nothing was hit does the visual effect using a far away point.

            {
                lineRenderers[index].positionCount = 2;
                lineRenderers[index].SetPositions(new Vector3[] { bulletSpawn.transform.position, bulletSpawn.transform.position + bulletSpawn.transform.forward * 1000.0f });

                StartCoroutine(TimedVisualEffect(index, null));
            }
        }
Exemplo n.º 2
0
        protected void OnTriggerEnter(Collider col)
        {
            ConductorBox conductorBox = col.GetComponent <ConductorBox>();

            // Check if the object collided have an conductor box and doesnt have any entity attached to.
            if (conductorBox == null || conductorBox.entity != null)
            {
                return;
            }

            print("Goint go electrify the object " + col.name);
            // If those requisites are satisfied, then this object must be an conductor (water). So, Electrify!
            conductorBox.Electrify(eletricDamage);

            Destroy(gameObject);
        }