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

Help with texture ongui

Discussion in 'Immediate Mode GUI (IMGUI)' started by Michcan, Jul 21, 2015.

  1. Michcan

    Michcan

    Joined:
    Jul 19, 2015
    Posts:
    9
    Hi, i dont know if this is the right place to post my doubt! sorry if its not, and sorry for my english (spanish is my first language)

    Im very new to unity, i want to place an image on the center of the screen only if a gameobject with the tag that i want is in the center of the screen.
    hope you understand... here is what i have now!


    public float X;
    public float Y;
    public Texture mano;
    bool puedeagarrarorchilito;

    // Use this for initialization
    void Start ()
    {
    puedeagarrarorchilito = false;
    }

    // Update is called once per frame
    void Update ()
    {
    RaycastHit hit;

    if (Physics.Raycast (transform.position, transform.forward, out hit, 20f)) {
    if (hit.collider.gameObject.tag == "Agarrables") {
    puedeagarrarorchilito = true;
    Debug.Log ("tocandofruta");
    } else {
    puedeagarrarorchilito = false;
    }
    }

    }
    void OnGUI ()
    {
    float Xcoord = X * Screen.width;
    float Ycoord = Y * Screen.height;
    if (puedeagarrarorchilito) {

    GUI.DrawTexture (new Rect (75, 99, Xcoord, Ycoord), mano);
    }
    }


    i get the debuglog right!
    but no image on screen
    any ideas?
    thanks1
     
  2. JFo

    JFo

    Joined:
    Dec 9, 2007
    Posts:
    217
    Your X and Y are zero. Initialize them like 0.5f.
     
  3. Michcan

    Michcan

    Joined:
    Jul 19, 2015
    Posts:
    9
    It worked thanks