Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

2D shop UI (Help Needed)

Discussion in 'Scripting' started by LuftWaffle3, Mar 14, 2018.

  1. LuftWaffle3

    LuftWaffle3

    Joined:
    Mar 9, 2018
    Posts:
    15
    I have been working on this for a few days now and I can't seem to figure this out i'm trying to make a dungeon crawler game with a shop and I have a box collider with no working screen that pops up when you press E is there a if statement that checks for the box collider so I can only access it in the box collider?

    Another thing is how would i be able to if i were to have a button that gives me say +1 attack damage how would I be able to add it to my player if i start at 1 attack damage?

    Thx in advance :)
     
  2. methos5k

    methos5k

    Joined:
    Aug 3, 2015
    Posts:
    8,712
    You could set a bool to true when you enter the collider, and to false upon exit. When you check for your key press, include the check for the bool being true.

    If you elaborate a bit on your second question, you might get a more quality answer..
    Is the attack boost permanent or temporary? Do you consider it increasing the base attack or adding something new on top (for other calculations), etc.. whatever you think is pertinent.
     
  3. LuftWaffle3

    LuftWaffle3

    Joined:
    Mar 9, 2018
    Posts:
    15
    if I had +1 attack and I got to the shop area and bought a attack damage +1 I would then have +2 attack

    also is there any way to have 2 canvases (working separately) in the same scene I have the shop menu working the same as my pause menu witch works off a canvas.
    because currently I cant get anything to pop up.
     
  4. methos5k

    methos5k

    Joined:
    Aug 3, 2015
    Posts:
    8,712
    Okay, well you can add to your attack damage, just like you described..

    Yes, you can have more than 1 canvas in the scene. Is your pause menu not popping up either?
     
  5. LuftWaffle3

    LuftWaffle3

    Joined:
    Mar 9, 2018
    Posts:
    15
    that's the only thing popping up 2D UI wise

    sorry for the delayed response I was busy this weekend
     
    Last edited: Mar 19, 2018
  6. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    9,859
    There's no secret formula to stuff like this; you just have to roll up your sleeves and figure out what's going on.

    Run your game. Now go to the Hierarchy tab, find your shop UI, and activate it manually using the Inspector. Do you see it? If not, why not — is it being covered by something else? Deactivate everything else. Is it inside some other GameObject that's inactive? Activate that. Is it positioned incorrectly? Fix it. Keep poking until you have manually caused your canvas content to appear in the game view.

    Now quit the game and do it again, to make sure you understand what the key problem(s) is/are.

    Now consider the code. Why isn't the code doing what you just did manually? Perhaps the code you think is running isn't even running. Put in a Debug.Log to be sure. If it's not, why not? Is that script even attached to anything? Is the object it's attached to active (and the script enabled)? If so, what's supposed to trigger that code? Call it from something more certain, like the Start method (which should also contain a Debug.Log to be sure it actually happens). Keep working your way backwards from the code you think should run, and forwards from whatever event or circumstances you think should run it, until they meet and you've got the code working.

    Now just make sure that code does the same thing as what you did manually, and your UI will appear.

    This is programming — there are a gazillion things that can go wrong, so if something's not working, you just have to figure out exactly what went wrong, and fix it.
     
  7. LuftWaffle3

    LuftWaffle3

    Joined:
    Mar 9, 2018
    Posts:
    15
    if I could figure it out I wouldn't need to ask the question in the first place

    //////shop UI code//////

    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    using UnityEngine.SceneManagement;

    public class ShopMenu : MonoBehaviour
    {
    public GameObject otherObject;
    public static bool GameIsPaused = false;
    public GameObject ShopMenuUI;
    // Update is called once per frame
    void Update ()
    {

    // if (otherObject.GetComponent<ShopArea>().InShopArea = true)
    // {
    if (Input.GetKeyDown (KeyCode.E))
    {
    if (GameIsPaused)
    {
    Resume ();
    } else
    {
    Pause ();
    }
    }
    // }
    }
    public void Resume ()
    {
    ShopMenuUI.SetActive (false);
    Time.timeScale = 1f;
    GameIsPaused = false;
    }

    void Pause ()
    {
    ShopMenuUI.SetActive (true);
    Time.timeScale = 0f;
    GameIsPaused = true;
    }
    public void ShopItems ()
    {

    }


    }
     
    Last edited: Mar 19, 2018
  8. LuftWaffle3

    LuftWaffle3

    Joined:
    Mar 9, 2018
    Posts:
    15
    I took my pause menu and copied for the shop but it just wont show up the same as the pause menu

    took the working pause menu prefab I had and copied it exactly for the shop and when I press E nothing pops up only the pause menu when I hit Esc and yes I do have it set to E for the shop
     
    Last edited: Mar 19, 2018
  9. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    9,859
    I don't believe you're really trying. Go back over all those suggestions I posted above. Actually do them.

    Sometimes just posting your code here (with code tags) will be enough for someone to spot a problem. But often the problem isn't code. If you really can't gather clues and problem-solve, then this may not be the hobby for you.
     
  10. LuftWaffle3

    LuftWaffle3

    Joined:
    Mar 9, 2018
    Posts:
    15
    Again if I wanted this criticism in stead of some real help would have not asked and I just don't know how to make it show up when I know it should work from what I can see in the code
     
  11. methos5k

    methos5k

    Joined:
    Aug 3, 2015
    Posts:
    8,712
    I honestly think you were given constructive feedback. When I read the long post above by @JoeStrout , all of the steps that he went over reminded me of what it's like each time I'm working through a debugging operation..
    Just my 2 cents. :)
     
  12. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    9,859
    Yeah, I don't know what else to say. You're right, from the code shown it should work. So it is something else, and I gave you the steps to figure out what that is. To get more help than that, somebody would have to sit down with you at your computer or over screen sharing and do those steps with you (or take a copy of the whole project and do them for you). If you want/need someone to do that, consider posting a small consulting job at UnityConnect.
     
  13. LuftWaffle3

    LuftWaffle3

    Joined:
    Mar 9, 2018
    Posts:
    15
    I figured it out but on my own
     
  14. LuftWaffle3

    LuftWaffle3

    Joined:
    Mar 9, 2018
    Posts:
    15
    but thx for the ideas