Exemplo n.º 1
0
    public override void UpdateInputAxis(float axis)
    {
        if (axis < axisOpeningThreshold)         //hand is opened
        {
            isOpen = true;
            if (itemHeld != null)
            {
                itemHeld.ReleaseItem();
                SendMessage("SetDefaultTarget", grabPoint.transform, SendMessageOptions.DontRequireReceiver);
                itemHeld = null;
            }
            grabPoint.SetActive(false);
        }
        else if (axis > axisClosingThreshold)         //hand is closed
        {
            isOpen = false;
            if (itemHeld == null && currentCollectableInRange != null)
            {
                grabPoint.SetActive(true);

                itemHeld = currentCollectableInRange;
                itemHeld.rigidbody.isKinematic = true;

                //HACK: Keeps the held object from flying away (should drop straight down)
                itemHeld.transform.position = grabPoint.transform.position + transform.forward * (itemHeld.transform.localScale.x - 1);

                itemHeld.GrabItem(grabPoint.rigidbody);
                itemHeld.rigidbody.isKinematic = false;
            }
        }
    }
Exemplo n.º 2
0
    public void SetHandClosed(float axis)
    {
        if (axis < axisOpeningThreshold)         //open hand
        {
            isOpen = true;
            if (itemHeld != null)
            {
                itemHeld.ReleaseItem();
            }
            grabPoint.SetActive(false);
        }
        else if (axis > axisClosingThreshold)
        {
            isOpen = false;
            if (currentCollectableInRange != null)
            {
                grabPoint.SetActive(true);

                itemHeld = currentCollectableInRange;
                itemHeld.rigidbody.isKinematic = true;
                itemHeld.transform.position    = grabPoint.transform.position;
                itemHeld.GrabItem(grabPoint.rigidbody);
                itemHeld.rigidbody.isKinematic = false;
            }
        }
    }
Exemplo n.º 3
0
    void ProcessState()
    {
        switch (currentState)
        {
        case FSM.State.Patrol:
            // Cycle through waypoints
            if (Vector3.Distance(this.transform.position, waypointList[nextWaypoint].position) <= 2.0f)
            {
                nextWaypoint++;
                if (nextWaypoint > waypointList.Length - 1)
                {
                    nextWaypoint = 0;
                }
            }
            // Move towards next target
            MoveAgent(waypointList[nextWaypoint].position);
            break;

        case FSM.State.Chase:
            // Chase the player
            MoveAgent(player.transform.position);
            if (Vector3.Distance(this.transform.position, player.transform.position) <= caughtPlayerDistanceThreshold)
            {
                if (CanAttack())
                {
                    player.rigidbody.AddForce((pushEntrance.position - player.transform.position) * 40, ForceMode.Impulse);
                    Transition(FSM.Trigger.EnemyDisappeared);
                    return;
                }
            }
            break;

        case FSM.State.Return:
            // Return home
            MoveAgent(waypointList[0].position);
            if (Vector3.Distance(this.transform.position, waypointList[0].position) <= 2.0f)
            {
                numReturnAfterAttacking++;
                if (numReturnAfterAttacking % 2 == 1)
                {
                    audio.clip = soundLaugh;
                    SubtitleManager.Instance.AddSubtitle("Ha. Ha.", 1.5f, Color.red);
                }
                else
                {
                    audio.clip = soundLament;
                    SubtitleManager.Instance.AddSubtitle("I wish I had a box.", 1.5f, Color.red);
                }
                audio.Play();
                SubtitleManager.Instance.Play();
                Transition(FSM.Trigger.ReachedBase);
            }
            break;

        case FSM.State.Pacified:
            MoveAgent(pacifyObject.transform.position);
            if (Vector3.Distance(this.transform.position, pacifyObject.transform.position) <= caughtPlayerDistanceThreshold)
            {
                navMeshAgent.Stop(true);
                if (grabbableItem != null)
                {
                    grabbableItem.SetGrabbable(false);
                    grabbableItem.ReleaseItem();
                    pacifyObject.rigidbody.isKinematic = true;
                    Destroy(grabbableItem);
                }
            }
            if (!happySoundPlayed && !audio.isPlaying)
            {
                audio.clip = soundHappy;
                audio.Play();
                happySoundPlayed = true;
                SubtitleManager.Instance.Stop();
                SubtitleManager.Instance.AddSubtitle("Oh my god. A box! <3", 2.0f, Color.magenta);
                SubtitleManager.Instance.Play();
            }
            break;
        }
        ;
    }