Author Topic: using singleton and NGUI's onclick in 2 scene  (Read 1328 times)

brian661

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 12
    • View Profile
using singleton and NGUI's onclick in 2 scene
« on: September 25, 2014, 05:04:52 AM »
In my game, there are 2 scene, A and B
 a Gameobject UIManager with a script UIControl is prefined defined in scene A.
 In the script, I have use the singleton pattern which I learnt here
http://unitypatterns.com/singletons/

What I would like to do is:
 1. Moving between scene with only 1 UIManager will be existed.
 2. every function will be in the UIControl script
 3. using NGUI's UIButton script to notify UIManager the onClick event

by using Singleton and dontDestroyOnLoad, 1.) have been done but I find that I have problem on 2 and 3
 As I am using Singleton, scene B will not have a UIManager Gameobject, hence I cannot drag the gameobject to the UIButton script.
 If I create a same object with same script, although I can drag the object to the onClick,
 the notify become back to none in the play mode.(and only one UIManager was existed as using singleton)

What should I do so that I can put every onClick event function in the same script?
And can set the notify of the onClick in the scene B?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: using singleton and NGUI's onclick in 2 scene
« Reply #1 on: September 25, 2014, 07:40:50 PM »
You will need to have buttons notify some script that actually exists in the scene. Maybe inside this script's function find the intended target -- by tag, or some other means -- and forward the event there.