Author Topic: How to make tooltip sprites that disappear when user touch outside?  (Read 5919 times)

leegod

  • Jr. Member
  • **
  • Thank You
  • -Given: 5
  • -Receive: 0
  • Posts: 90
    • View Profile
I am making mobile game.

When user touch some card in my game, I want to pop up description window. So I made that with UISprite's bundles.

And now I want to make,

[when user touch other screen area or ngui objects than the description window, window disappear automatically]

Important thing is when user touch other button(or other touchable ngui interface) outside of the description window, button's function should work and also description window also should disappear.

How can I make this?

Thanks.

« Last Edit: October 29, 2014, 08:41:05 PM by leegod »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: How to make tooltip sprites that disappear when user touch outside?
« Reply #1 on: October 30, 2014, 12:20:23 PM »
UITooltip.Show(...); to show it,

UITooltip.Hide(); to hide it.

leegod

  • Jr. Member
  • **
  • Thank You
  • -Given: 5
  • -Receive: 0
  • Posts: 90
    • View Profile
Re: How to make tooltip sprites that disappear when user touch outside?
« Reply #2 on: October 30, 2014, 08:03:24 PM »
UITooltip.Show(...); to show it,

UITooltip.Hide(); to hide it.

Thx.

But for call .Hide(), how to catch user's last touch is not the rectangle of description window?


ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: How to make tooltip sprites that disappear when user touch outside?
« Reply #3 on: November 01, 2014, 04:59:37 AM »
UICamera.onClick = YourDelegate;

Check inside this function to see if the click is inside or outside.

leegod

  • Jr. Member
  • **
  • Thank You
  • -Given: 5
  • -Receive: 0
  • Posts: 90
    • View Profile
Re: How to make tooltip sprites that disappear when user touch outside?
« Reply #4 on: November 02, 2014, 09:44:10 PM »
UICamera.onClick = YourDelegate;

Check inside this function to see if the click is inside or outside.

1. Sorry but, I wrote like this, but does not work well.
Can you write right method?

2. And this script should attached to ngui camera?

  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4. public class UICameraScript : MonoBehaviour {
  5.         public delegate void Check();
  6.         void Start () {
  7.                 UICamera.onClick = new Check();
  8.         }
  9.         void Check(){
  10.                 RaycastHit rh = UICamera.lastHit;
  11.                 if(rh.collider.gameObject.name != "Description"){
  12.                         CloseWindow();
  13.                 }
  14.         }
  15.         void CloseWindow(){
  16.  
  17.         }
  18.         void OnClick(){
  19.                 print("asdf");
  20.         }
  21. }
  22.  

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: How to make tooltip sprites that disappear when user touch outside?
« Reply #5 on: November 03, 2014, 06:40:25 AM »
You need to check C#'s documentation for how delegates work.
  1. public class UICameraScript : MonoBehaviour
  2. {
  3.     void Start ()
  4.     {
  5.         UICamera.onClick = Check;
  6.     }
  7.  
  8.     void Check (GameObject go)
  9.     {
  10.         if(go == null || go.name != "Description")
  11.             CloseWindow();
  12.     }
  13.  
  14.     void CloseWindow(){ }
  15. }
« Last Edit: November 04, 2014, 09:15:10 AM by ArenMook »

leegod

  • Jr. Member
  • **
  • Thank You
  • -Given: 5
  • -Receive: 0
  • Posts: 90
    • View Profile
Re: How to make tooltip sprites that disappear when user touch outside?
« Reply #6 on: November 03, 2014, 08:00:02 AM »
Thx, but your script error occurs...

Assets/Script/UI/UICameraScript.cs(7,26): error CS0123: A method or delegate `UICameraScript.Check()' parameters do not match delegate `UICamera.VoidDelegate(UnityEngine.GameObject)' parameters

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: How to make tooltip sprites that disappear when user touch outside?
« Reply #7 on: November 04, 2014, 09:15:20 AM »
Edited the code.