Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

canvas enable/ input field difficulty

Discussion in 'UGUI & TextMesh Pro' started by JackSparrow1, Jul 31, 2015.

  1. JackSparrow1

    JackSparrow1

    Joined:
    Jun 21, 2015
    Posts:
    16
    Unity 4.6.1 JS

    Im trying to utilize a user input of a numerical value, that i can then compare to the available range defined by resources available.

    Ive look at several examples, all of which do not work, either the actual script instruction spamming a unity systems error take for e.g the below, or not being able to find the instruction set components i need to get for another example a string back to a numerical VAL.

    Ive tried to make a work around and use the UI canvas system to handle the input field & restrictions, but i can not find a way or working JS example of enabling the specific canvas.
    ive tried " var buildMenu : Canvas; Var Canvas: Canvas = GetComponent ("buildMenucanvas");
    buildMenu.enabled =true;

    but unity cant process it, and i can not find references in forum, google search or in the unity manual, that shows practical application examples of useage. Im not asking for the script to be written for me, I just want references and an example of how i go about this. Unity it seems is very unfriendly for anyone new to it, to learn, even with a 30 year assemble background like myself

    ive included
    import UnityEngine;
    import UnityEngine.UI
    import System.Collections;

    // maxbuild = maximum amount of tanks that an be built
    num = Mathf.Clamp(0, maxbuild)

    id prefer to stick with just script, but can not find a soultion to this
     
  2. JackSparrow1

    JackSparrow1

    Joined:
    Jun 21, 2015
    Posts:
    16
    im also trying to use, but im getting "BCE0019 'enabled' is not a member of UnityEngine.GameObject"

    var mygameobject: GameObject;

    mygameobject = GameObject.Find("buildMenu");
    mygameobject.enabled = true;
     
  3. JackSparrow1

    JackSparrow1

    Joined:
    Jun 21, 2015
    Posts:
    16
    Well, I figured out how to switch objects on/off from within script. Problem with canvas or objects attached to canvas is they get drawn behing my scripted gui stuff. setting GUI.Depth to script gui dont do anything as i cant set unity editor canvas/elements HUI/UI depth. If i change Z on position that too has no effect as the rest of my gui is drawn & handled in script. Ive also tried setting which layer the canvas/elements are on but still no effect.
    I guess unity renders all scripted GUI stuff last and on top of other objects in a chronological order.
    Is there any way to alter unitys engine gui draw depth, or if anyone knows a way to solve this. Id still prefer to do my input field in script, but cant figure it out or find working examples to learn from.
     
  4. JackSparrow1

    JackSparrow1

    Joined:
    Jun 21, 2015
    Posts:
    16
    Ok ive resolved all of the issues.
    ill post my solutions, once ive finished codeing it all. Sometime tomorrow.
     
  5. JackSparrow1

    JackSparrow1

    Joined:
    Jun 21, 2015
    Posts:
    16
    The solution is " i figured it all out myself".
    The on/off of game object was simplest, the issue i had was not attaching the gameobject in the editor: Doh!
    very dissheartening that no-one here could provide direction.

    The issue of getting editor UI to layer correctly, just took a bit of intelligence, im sure you can all work it out, if your on my good list and need to know ill provide full script with detailed explanation of all.

    The issue of getting data between objects and script and back was also simple, again once i knew how unity handles such.

    Its not my prefered method, of using script & editor, when id prefer it all in script. but without any indications forthcomming from the community that read this thread, it will have to do. All in all it works 100%