Example #1
0
    void Update()
    {
        if(lockActions == true)
        {
            //do nothing
            chewG.text = ("Chewed Gum: " + chewedGum);
            bubGum.text = ("Bubble Gum: " + bubbleGum + "  press e");
            HP.text = ("Health: " + health);
            if ((invOn == true) && (Input.GetKeyDown("e")) && (health < 10))
            {
                health = 12;
                bubbleGum -= 1;
            }

            //inventory controls
            if (Input.GetKeyDown("i"))
            {
                if (invOn == false)
                {
                    inv.Activate();
                    invOn = true;
                }
                else
                {
                    inv.DeActivate();
                    invOn = false;
                }
            }
        }
        else
        {
            //keeping track of player stats to bring to combatscene
            PlayerPrefs.SetInt("hp", health);
            PlayerPrefs.SetInt("armor", armor);
            PlayerPrefs.SetInt("attack", attack);
            PlayerPrefs.SetInt("fastness", speed);

            //inventory updating
            chewG.text = ("Chewed Gum: " + chewedGum);
            bubGum.text = ("Bubble Gum: " + bubbleGum + "  press e");
            HP.text = ("Health: " + health);

            if ((invOn == true) && (Input.GetKeyDown("e")) && (health < 12))
            {
                health = 12;
                bubbleGum -= 1;
            }

            //movement code
            if ((Input.GetKeyDown("down")) || (Input.GetKeyDown("s")))
            {
                if (yPos > 1)
                {
                    yPos -= 1;
                    if (yPos < 0)
                    {
                        yPos = +1;
                    }
                    else if (mapGrid[xPos, yPos] == 2)
                    {
                        yPos += 1;
                    }
                    else
                    {
                        PlayerPrefs.SetInt("xPs", xPos);
                        PlayerPrefs.SetInt("yPs", yPos);
                        transform.Translate(0, -1, 0);
                        //moved = true;
                    }
                }
                else
                {
                    Debug.Log("Cannot travel out of map");
                }
            }
            if ((Input.GetKeyDown("up")) || (Input.GetKeyDown("w")))
            {
                if (yPos < mapSizeY - 2)
                {
                    yPos += 1;
                    if (yPos > (mapSizeY - 1))
                    {
                        yPos = +1;
                    }
                    else if (mapGrid[xPos, yPos] == 2)
                    {
                        yPos -= 1;
                    }
                    else
                    {
                        PlayerPrefs.SetInt("xPs", xPos);
                        PlayerPrefs.SetInt("yPs", yPos);
                        transform.Translate(0, +1, 0);
                        //moved = true;
                    }
                }
                else
                {
                    Debug.Log("Cannot travel out of map");
                }
            }
            if ((Input.GetKeyDown("left")) || (Input.GetKeyDown("a")))
            {
                if (xPos > 1)
                {
                    xPos -= 1;
                    if (xPos < 0)
                    {
                        xPos = +1;
                    }
                    else if (mapGrid[xPos, yPos] == 2)
                    {
                        xPos += 1;
                    }
                    else
                    {
                        PlayerPrefs.SetInt("xPs", xPos);
                        PlayerPrefs.SetInt("yPs", yPos);
                        transform.Translate(-1, 0, 0);
                        // moved = true;
                    }
                }
                else
                {
                    Debug.Log("Cannot travel out of map");
                }
            }
            if ((Input.GetKeyDown("right")) || (Input.GetKeyDown("d")))
            {
                if (xPos < mapSizeX - 2)
                {
                    xPos += 1;
                    if (xPos > (mapSizeX - 1))
                    {
                        xPos = -1;
                    }
                    else if (mapGrid[xPos, yPos] == 2)
                    {
                        xPos -= 1;
                    }
                    else
                    {
                        PlayerPrefs.SetInt("xPs", xPos);
                        PlayerPrefs.SetInt("yPs", yPos);
                        transform.Translate(+1, 0, 0);
                        //moved = true;
                    }
                }
                else
                {
                    Debug.Log("Cannot travel out of map");
                }
            }

            //inventory controls
            if (Input.GetKeyDown("i"))
            {
                if (invOn == false)
                {
                    inv.Activate();
                    invOn = true;
                }
                else
                {
                    inv.DeActivate();
                    invOn = false;
                }
            }

            //shop stuff
            if (xPos == 5 && yPos == 12)
            {
                shop.Activate();
                lockActions = true;
            }
        }
    }