Author Topic: The variable tweenTarget of buttonClick has not been assigned.  (Read 3981 times)

fghjru

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 8
    • View Profile
SetState(State.Disabled, false); cause an error: "The variable tweenTarget of buttonClick has not been assigned". What am I doing wrong?

  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4.  
  5. public class buttonClick : UIButton
  6. {
  7.     protected override void OnClick()
  8.     {
  9.         Debug.Log("Super Effect!");
  10.     }
  11.  
  12.     protected override void OnEnable()
  13.     {
  14.    
  15.         StartCoroutine(wait(0));
  16.         Debug.Log("OnEnable()");
  17.     }
  18.    
  19.  
  20.     public void Init(Vector3 indent, System.Action action, EventDelegate.Callback callback)
  21.     {
  22.         this.indent = indent;
  23.        
  24.         this.Clicked = action;
  25.         this.callback = callback;
  26.  
  27.         UIEventTrigger trigger = GetComponent<UIEventTrigger>();
  28.         EventDelegate.Add(trigger.onHoverOut, callback);
  29.     }
  30.  
  31.     IEnumerator wait(float waitTime)
  32.     {
  33.         yield return new WaitForSeconds(waitTime);
  34.  
  35.         transform.localPosition += this.indent;
  36.         SetState(State.Disabled, false); // Error
  37.     }}
  38.  

fghjru

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 8
    • View Profile
Re: The variable tweenTarget of buttonClick has not been assigned.
« Reply #1 on: April 01, 2014, 10:03:49 AM »
And I made a class derived from UIButton, and methods OnEnable(), OnClick() are overrided now. I don't understand how does void OnClick() work, when class inherited not from UIButton, but from MonoBehaviour?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: The variable tweenTarget of buttonClick has not been assigned.
« Reply #2 on: April 01, 2014, 10:45:41 AM »
OnClick is a regular NGUI event sent by the UICamera. Check the documentation for the UICamera for a full list. All colliders are able to receive NGUI events -- it's a generic event system that's not limited to the UI.

There is no need to derive anything from UIButton. Why are you doing that? UIButton is a stand-alone component providing specific functionality.

fghjru

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 8
    • View Profile
Re: The variable tweenTarget of buttonClick has not been assigned.
« Reply #3 on: April 01, 2014, 11:18:35 AM »
Understood, thank you