Tasharen Entertainment Forum

Support => NGUI 3 Support => Topic started by: vikti on December 17, 2014, 02:24:48 PM

Title: [SOLVED]UICamera.onClick does not exist...i
Post by: vikti on December 17, 2014, 02:24:48 PM
Hi,

I try to set an event delegate but I have the bellow error

  1. Assets/Libraries/Wizar/UIInteraction/OpenBottomSheet.cs(30,62): error CS1061: Type `UICamera' does not contain a definition for `OnClick' and no extension method `OnClick' of type `UICamera' could be found (are you missing a using directive or an assembly reference?)
  2.  

Here is my code :

  1. using UnityEngine;
  2. using System.Collections;
  3. using Wizar;
  4.  
  5. public class OpenBottomSheet : MonoBehaviour {
  6.  
  7.         private Transform _tweenTarget;
  8.         private bool _isDisplayed = false;
  9.         public Vector3 hover = Vector3.zero;
  10.         public Vector3 pressed = new Vector3(0f, 150f);
  11.         public float duration = 0.2f;
  12.  
  13.         Vector3 mPos;
  14.         bool mStarted = false;
  15.  
  16.         void Start(){
  17.                 _tweenTarget = transform.GetChild(1);
  18.  
  19.                 if (!mStarted)
  20.                 {
  21.                         mStarted = true;
  22.                         mPos = _tweenTarget.localPosition;
  23.                 }
  24.         }
  25.  
  26.         // Shout that a new bottom sheet is going to be opened
  27.         void OnEnable () {
  28.                 MapEventsManager.Trigger("OnOpeningBottomSheet");
  29.                 MapEventsManager.OnOpeningBottomSheet += Close;
  30.                 UICamera.mainCamera.GetComponent<UICamera>().onClick += Open;
  31.         }
  32.        
  33.         void OnDisable () {
  34.                 MapEventsManager.OnOpeningBottomSheet -= Close;
  35.                 UICamera.mainCamera.GetComponent<UICamera>().onClick -= Open;
  36.         }
  37.  
  38.         void Open(){
  39.                 if (!_isDisplayed){
  40.                         TweenPosition.Begin(_tweenTarget.gameObject, duration, mPos + pressed).method = UITweener.Method.EaseInOut;
  41.                         _isDisplayed = true;
  42.                 }
  43.         }
  44.  
  45.         void Close(){
  46.                 if (_isDisplayed){
  47.                         TweenPosition.Begin(_tweenTarget.gameObject, duration, mPos).method = UITweener.Method.EaseInOut;
  48.                         _isDisplayed = false;
  49.                 }
  50.         }
  51.  
  52. }
  53.  

I tried with Onclick and onClick.

I am new to delegate stuff...
Title: Re: UICamera.onClick does not exist...i
Post by: ArenMook on December 17, 2014, 03:33:49 PM
UICamera.onClick is a static delegate. There is no need for a camera reference.

Change:
  1. UICamera.mainCamera.GetComponent<UICamera>().onClick += Open;
to simply:
  1. UICamera.onClick += Open;
Title: Re: UICamera.onClick does not exist...i
Post by: vikti on December 18, 2014, 03:32:27 AM
I found my error. (Indeed, your code is my first version)

I simply put it in a OnEnable() so the Static Class were not loaded yet...