Пример #1
0
    /**
     * Date:             May 5, 2017
     * Author:           Jay Coughlan
     * Interface:        void OnTriggerExit()
     * Description:
     *                   Updates an object when it leaves the collider area.
     */
    private void OnTriggerExit(Collider other)
    {
        GameObject go = other.gameObject;
        int        index;

        if (debug)
        {
            Debug.Log("Removing " + go.name + " at " + go.transform.position + "; distance: " + Vector3.Distance(this.transform.position, go.transform.position));
        }
        switch (other.tag)
        {
        case "Entrance":
        //we want entrance to fall through to obstacles because the behavior is the same
        case "Walls":
            if (collidedObjects.Contains(go))    //we want to make sure this object wasn't, by some miracle, removed from the list prematurely
            {
                //first get the objects index
                index = collidedObjects.IndexOf(go);
                //here we decide what we want to do when the object leaves the area
                if (collidedMinDistances[index] < min)
                {
                    //within the bounds of our innermost layer. Likely we should not hit this either, as a death should be dealt with in the update loop
                }
                else if (collidedMinDistances[index] > min && collidedMinDistances[index] < layer2)
                {
                    //second most inner layer, many many points
                }
                else if (collidedMinDistances[index] > layer2 && collidedMinDistances[index] < layer3)
                {
                    //third most inner layer, some points maybe?
                }
                else if (collidedMinDistances[index] > layer3 && collidedMinDistances[index] < max)
                {
                    //if it is within the bounds of our outer layer
                }
                else
                {
                    //this statement is here just in case, but should never be encountered since the distance would have to be larger than the collider
                }
                //now we remove it's distance
                collidedMinDistances.RemoveAt(index);
                collisions.RemoveAt(index);
                collisionAngles.RemoveAt(index);
                //collidedNames.RemoveAt(index);
                //now we remove the object from the list
                collidedObjects.Remove(go);
            }

            //pmScript.bounce();
            break;

        case "Obstacle":
            if (collidedObjects.Contains(go))    //we want to make sure this object wasn't, by some miracle, removed from the list prematurely
            {
                //first get the objects index
                index = collidedObjects.IndexOf(go);
                //here we decide what we want to do when the object leaves the area
                if (collidedMinDistances[index] < min)
                {
                    //within the bounds of our innermost layer. Likely we should not hit this either, as a death should be dealt with in the update loop
                }
                else if (collidedMinDistances[index] > min && collidedMinDistances[index] < layer2)
                {
                    //second most inner layer, many many points
                    pmScript.addPoints(3);
                }
                else if (collidedMinDistances[index] > layer2 && collidedMinDistances[index] < layer3)
                {
                    //third most inner layer, some points maybe?
                    pmScript.addPoints(2);
                }
                else if (collidedMinDistances[index] > layer3 && collidedMinDistances[index] < max)
                {
                    //if it is within the bounds of our outer layer
                    pmScript.addPoints();
                }
                else
                {
                    //this statement is here just in case, but should never be encountered since the distance would have to be larger than the collider
                }
                //now we remove it's distance
                collidedMinDistances.RemoveAt(index);
                collisions.RemoveAt(index);
                collisionAngles.RemoveAt(index);
                //collidedNames.RemoveAt(index);
                //now we remove the object from the list
                collidedObjects.Remove(go);
            }
            break;

        case "Consumable":
            if (collidedObjects.Contains(go))    //we want to make sure this object wasn't, by some miracle, removed from the list prematurely
            {
                //first get the objects index
                index = consumedObjects.IndexOf(go);
                //now we remove it's distance
                consumedDistances.RemoveAt(index);
                consumedCollisions.RemoveAt(index);
                consumedAngles.RemoveAt(index);
                //collidedNames.RemoveAt(index);
                //now we remove the object from the list
                collidedObjects.Remove(go);
            }
            break;

        case "Player":
            break;

        case "Start Volume":
            break;

        case "End Volume":
            break;

        default:
            break;
        }
    }