Ejemplo n.º 1
0
    // Update is called once per frame
    void FixedUpdate()
    {
        if (usingItem && !menu.isOpen)
        {
            if (useTimer.CheckTimer())
            {
                Vector2    coord   = map.getTileFromPosition(transform.position.x, transform.position.y);
                GameObject a       = Instantiate(inventory.trapPrefab);
                Vector2    tilePos = map.getTilePosition((int)coord.x, (int)coord.y);
                a.transform.position = new Vector2(tilePos.x, tilePos.y);
                a.GetComponent <TrapCollisionEvent>().item = playerStats.traps[inventory.trapOn];
                a.GetComponent <TrapCollisionEvent>().UpdateData();
                inventory.TrashItem(playerStats.traps[inventory.trapOn], 1);
                usingItem = false;
                useTimer.StopTimer();
                timeBar.gameObject.SetActive(false);
            }
            else
            {
                useTimer.TimerUpdate();
                timeBar.value = useTimer.GetPercent();
            }
        }
        else
        {
            animator.SetFloat("XVeloc", horizontalInput);
            animator.SetFloat("YVeloc", verticalInput);
            facing = GetFacing();
            if (horizontalInput != 0 && verticalInput != 0)
            {
                horizontalInput *= normalizeSpeed;
                verticalInput   *= normalizeSpeed;
            }

            playerBody.velocity = new Vector2(horizontalInput * speed / halfSpeed, verticalInput * speed / halfSpeed);
        }
    }