Пример #1
0
        private void OnTriggerStay(Collider other)
        {
            if (other.gameObject.CompareTag("TrapSquare"))
            {
                trapUI.UpdateTrapUIDetails(trapState, trapGnomeOn, selectedTrap);

                if (other.gameObject.GetComponent <TrapPlacementArea>() && !currentTrapLocation)
                {
                    currentTrapLocation = other.gameObject.GetComponent <TrapPlacementArea>();
                    trapGnomeOn         = currentTrapLocation.currentTrap;
                }

                // check to if there is a trap here...
                // if not allow the user to place a trap here....
                if (currentTrapLocation && !other.gameObject.GetComponent <TrapPlacementArea>().hasTrap)
                {
                    trapState = TrapStates.PlaceTrap;
                }
                else if (currentTrapLocation && other.gameObject.GetComponent <TrapPlacementArea>().hasTrap)
                {
                    // else allow the user to pickup what is there.
                    trapState = TrapStates.PickupTrap;
                }

                // updates the trap location
                if (trapGnomeOn != currentTrapLocation.currentTrap)
                {
                    trapGnomeOn = currentTrapLocation.currentTrap;
                }
            }
        }
Пример #2
0
 private void OnCollisionEnter2D(Collision2D other)
 {
     if (_trapState == TrapStates.NONE)
     {
         if (other.gameObject.tag == "Player")
         {
             _trapState = TrapStates.TRIGGERED;
         }
     }
 }
Пример #3
0
 private void OnTriggerExit(Collider other)
 {
     // resets the current trap and gnome state on exit
     if (other.gameObject.CompareTag("TrapSquare"))
     {
         trapState           = TrapStates.NoTraps;
         currentTrapLocation = null;
         trapGnomeOn         = TrapTypes.None;
         trapUI.HideTrapUI();
     }
 }
Пример #4
0
        private void Update()
        {
            switch (currState)
            {
            case TrapStates.INACTIVE:
                // Out of view
                currTime += Time.deltaTime;
                if (currTime >= timeToDeploy)
                {
                    attackBox.enabled = false;
                    trapAnimation.SetBool("isAttacking", false);
                    currState = TrapStates.DEPLOYING;
                    currTime  = 0f;
                }
                break;

            case TrapStates.DEPLOYING:
                // Moving into pos
                currTime += Time.deltaTime;
                MoveToPosition(setTrapPos.position, TrapStates.WAITING);
                break;

            case TrapStates.WAITING:
                // Preparing to attack
                currTime += Time.deltaTime;
                if (currTime >= timeToStrike)
                {
                    attackBox.enabled = true;
                    trapAnimation.SetBool("isAttacking", true);
                    currState = TrapStates.ATTACK;
                    currTime  = 0f;
                }
                break;

            case TrapStates.ATTACK:
                if (trapAnimation.GetCurrentAnimatorStateInfo(0).IsName("DONE"))
                {
                    currState = TrapStates.RETREAT;
                }
                break;

            case TrapStates.RETREAT:
                MoveToPosition(origPos, TrapStates.INACTIVE);
                break;
            }
        }
Пример #5
0
    // Update is called once per frame
    void Update()
    {
        switch (_trapState)
        {
        case TrapStates.NONE:
            //Check collider
            break;

        case TrapStates.TRIGGERED:
            _animator.SetBool("startAnimation", true);
            _trapState = TrapStates.INACTIVE;
            break;

        case TrapStates.ANIMATING:
            break;

        case TrapStates.INACTIVE:
            break;
        }
    }
Пример #6
0
        /// <summary>
        /// Updates the trap UI
        /// </summary>
        /// <param name="state">The state of the trap</param>
        /// <param name="type">The type of trap on the trap currently</param>
        /// <param name="userTrap">The trap type the user has active</param>
        public void UpdateTrapUIDetails(TrapStates state, TrapTypes type, TrapTypes userTrap)
        {
            if (state.Equals(TrapStates.PlaceTrap))
            {
                prefabInstance.GetComponentsInChildren <Text>()[0].text = "Place " + userTrap.ToString() + " Trap";
            }
            else if (state.Equals(TrapStates.PickupTrap))
            {
                prefabInstance.GetComponentsInChildren <Text>()[0].text = "Pickup " + type.ToString() + " Trap";
            }

            prefabInstance.GetComponentsInChildren <Text>()[1].text = userTrap.ToString() + " Trap Selected";

            if (isGamepad)
            {
                if (state.Equals(TrapStates.PlaceTrap))
                {
                    prefabInstance.GetComponentsInChildren <Text>()[2].text = controllerPlace;
                }
                else if (state.Equals(TrapStates.PickupTrap))
                {
                    prefabInstance.GetComponentsInChildren <Text>()[2].text = controllerPickup;
                }

                prefabInstance.GetComponentsInChildren <Text>()[3].text = controllerToggle;
            }
            else
            {
                if (state.Equals(TrapStates.PlaceTrap))
                {
                    prefabInstance.GetComponentsInChildren <Text>()[2].text = keyboardPlace;
                }
                else if (state.Equals(TrapStates.PickupTrap))
                {
                    prefabInstance.GetComponentsInChildren <Text>()[2].text = keyboardPickup;
                }

                prefabInstance.GetComponentsInChildren <Text>()[3].text = keyboardToggle;
            }
        }
Пример #7
0
        private void MoveToPosition(Vector2 destination, TrapStates stateToEndIn)
        {
            if (Mathf.Abs(Vector2.Distance(destination, trapRB.position)) >= 0.1f && currTime < 1.5f)
            {
                Vector2 newVelocity = (destination - trapRB.position) * Time.deltaTime;

                if (hasBeenSetOff == true)
                {
                    trapRB.velocity = newVelocity.normalized * captureSpeed;
                }
                else
                {
                    trapRB.velocity = newVelocity.normalized * moveSpeed;
                }
            }
            else
            {
                currTime               = 0f;
                trapRB.velocity        = Vector2.zero;
                trapRB.angularVelocity = 0f;
                currState              = stateToEndIn;
            }
        }
Пример #8
0
 private void Start()
 {
     origPos   = trapRB.position;
     currState = TrapStates.INACTIVE;
 }
Пример #9
0
 public void Begin()
 {
     animHandler.PlayActivationAnimation();
     state = TrapStates.casting;
 }
Пример #10
0
 public void Finish()
 {
     activationTimer = activationInterval;
     state           = TrapStates.idling;
 }
Пример #11
0
 public void setInactive()
 {
     _trapState = TrapStates.INACTIVE;
 }
Пример #12
0
 // Start is called before the first frame update
 void Start()
 {
     _trapState = TrapStates.NONE;
     _collider  = GetComponent <BoxCollider2D>();
     _animator  = GetComponent <Animator>();
 }