Exemplo n.º 1
0
    public int TransportObject(InteractionObject whichObject, GameObject whichGoal, WalkToGoal walktogoal, PickUp pickup, float pickuptime, Vector3 holdpointPosition, Vector3 holdPointRotation, int cascade)
    {
        if (cascade == 0) // first communicate some basics to pickup script
        {
            pickup.SetPickUpTime(pickuptime);
            pickup.SetCurrentIO(whichObject);
            cascade++;
        }

        if (cascade == 1) // walk to the object
        {
            // public bool WalkTo(Transform CurrentGoal, bool DrawPath, float maxspeed, float mindist, float anglecut) // to check what the parameters mean
            bool ObjectReached = walktogoal.WalkTo(whichObject.transform, false, 0.4f, 0.2f, 120); // walk towards object to be pickup
            if (ObjectReached)
            {
                cascade++;
            }
        }

        if (cascade == 2)                                              // pick it up
        {
            pickup.SetHoldPoint(holdpointPosition, holdPointRotation); // tell script how to hold this object. This is somehow overwritten if in cascade==0. Here it is called multiple times, but it's computationally light so that's ok
            float pickedup = pickup.PickUpObject(whichObject);         // returns value from 0 to 1 indicating when it has picked up the object
            if (pickedup > 0.50)
            {
                cascade++;
            }                                   // start walking towards goal before reaching 1, that is before object is perfectly in place. This gives a more fluent movement.
        }

        if (cascade == 3) // walk to the goal
        {
            bool GoalReached = walktogoal.WalkTo(whichGoal.transform, false, 0.4f, 0.2f, 120);
            if (GoalReached)
            {
                cascade++;
            }
        }

        if (cascade == 4) // drop object
        {
            float dropped = pickup.DropObject(whichGoal.transform);
            if (dropped > 0.99f)
            {
                pickup.LetGo();
                cascade++;
            }
        }

        return(cascade);
    }