Пример #1
0
    protected void Interact(Collider other)
    {
        // Attempt to interact with this by checking if its an appropriate object.
        IWeaponSpawn otherObject = other.gameObject.GetComponent <IWeaponSpawn>();

        if (otherObject != null)
        {
            // Make sure this bullet isn't interacting with a bullet from the same Shooter.
            if (GetOrigin().Equals(otherObject.GetOrigin()))
            {
                return;
            }
        }

        // Everything checks out!
        TypeSizeController.Interact(this.gameObject, other.gameObject);
    }
Пример #2
0
    /// <summary>
    /// Controls what happens when the laser raycasts and hits something.
    /// This will shorten the length of the LineRenderer so that it meets the
    /// closest object in the given hits.
    /// </summary>
    /// <param name="hit">List of hits</param>
    protected virtual void OnRaycastHit(RaycastHit[] hits)
    {
        // Change the points of the laser so that it only stretches until the hit.
        currentLength = Mathf.Abs(hits[0].point.x);
        Vector3 point = transform.InverseTransformPoint(hits[0].point);

        laserBeam.SetPosition(0, point);
        laserBeam.SetPosition(1, point);

        // Attempt to interact with these objects.
        RaycastHit firstHit = hits[0];
        GameObject other    = firstHit.collider.gameObject;

        if (((1 << other.gameObject.layer) & collideWith) == 0)
        {
            return;
        }

        IWeaponSpawn spawn = other.gameObject.GetComponent <IWeaponSpawn>();

        if (spawn != null)
        {
            // Make sure this bullet isn't interacting with a bullet from the same Shooter.
            if (gameObject.Equals(spawn.GetOrigin()))
            {
                return;
            }
        }

        // Everything checks out!
        TypeSizeController.Interact(gameObject, other);


        // On default, attempt to create a laser reflection, if allowed to.
        if (!isReflecting)
        {
            laserBeam.SetPosition(2, Vector3.zero);
        }
        else
        {
            StartCoroutine(Reflect(firstHit));
        }
    }