Author Topic: TweenAlpha and UIPanel Help needed  (Read 4507 times)

Reahreic

  • Guest
TweenAlpha and UIPanel Help needed
« on: August 23, 2013, 05:47:11 PM »
From what i've read you can use TweenAlpha on a UIPanel, however regardless of my implementation i receive errors. The documentation located at http://www.tasharen.com/ngui/docs/class_tween_alpha.html while is straight forward to use is a little lacking in examples making debugging difficult.

I am attempting to fade a UIPanel in then once complete call another function. I am rather new to unity, C# and NGUI.

I have a UIPanel in my scene called panelSplash that is assigned to the panelSplash field of the following script that is attached to my primary game obeject:
  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4. public class ShowMenu : MonoBehaviour {
  5.        
  6.         public UIPanel panelSplash;
  7.         private TweenAlpha twnA;
  8.        
  9.         // Use this for initialization
  10.         void Start() { 
  11.                 StartCoroutine(ShowSplash());
  12.         }
  13.        
  14.         // Update is called once per frame
  15.         void Update() {
  16.        
  17.         }
  18.        
  19.         IEnumerator ShowSplash(){
  20.                 yield return new WaitForSeconds(1.5f);
  21.                 twnA = TweenAlpha.Begin(panelSplash, 3f, 1f);
  22.                 twnA.callWhenFinished = "StepTwo";
  23.         }
  24.  
  25.         void StepTwo(){
  26.                 Debug.Log("Splash Panel Faded In");
  27.         }
  28. }
  29.  
The following errors are being logged when i just use the game object in TweenAlpha.begin(panelSplash,...
CS1502: The best overloaded method match for `TweenAlpha.Begin(UnityEngine.GameObject, float, float)' has some invalid arguments.
CS1503: Argument `#1' cannot convert `UIPanel' expression to type `UnityEngine.GameObject'

and if i call TweenAlpha.Begin(panelSplash.gameObject,....... i get the Object reference not set to an instance of an object even though I've dragged the panels game object to the script's panelSplash field in the inspector.

sisso

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 1
  • Posts: 46
    • View Profile
Re: TweenAlpha and UIPanel Help needed
« Reply #1 on: August 23, 2013, 08:13:32 PM »
Read again:

Quote
CS1503: Argument `#1' cannot convert `UIPanel' expression to type `UnityEngine.GameObject'

So, you are trying to give a UIPanel where it ask for a GameObject. UIPanel is a Component, from a Component you can access the GameObject by gameObject property. You must change for something like

  1. TweenAlpha.Begin(panelSplash.gameObject, 3f, 1f);

Sorry to say that. But it is very simple programing problem, an app could sove it automatically. If you don't study programing you will not go to far. And normally, nobody will answer these type of questions.

Reahreic

  • Guest
Re: TweenAlpha and UIPanel Help needed
« Reply #2 on: August 24, 2013, 03:41:04 PM »
As stated in the last sentence of the post.

Quote
and if i call TweenAlpha.Begin(panelSplash.gameObject,....... i get the Object reference not set to an instance of an object even though I've dragged the panels game object to the script's panelSplash field in the inspector.

I went to bed and restarted unity this morning and all of a sudden, the above mentioned second error no longer appeared. I'm chalking this up to the unity inspector not assigning the component correctly when dragged to the available slot in the inspector. (internet says it's a unity quirk)

------

On a side note, i have built CMS's (Content management systems) in PHP, actionscript and javascript that bypass local and network level security for clients during my day job and categorize myself as an intermediate level programmer, however i am new to C#, unity and it's object hierarchy and apparent quirks. (read: vague understanding of Unity components, prefabs and gameobjects).

I would love to find a list of unity and/or ngui quirks that i can read through in order to memorize them and as such be able to determine what errors are derived from unity, from plugins and what is just a generic code error due to not being fully versed in the unity IDE and it's object hierarchy.

I do think that NGUI is a great utility which many people have identified as a great stock GUI replacement, but you have to remember that not everyone who uses unity has the luxury of years of unity's IDE knowledge or working in it 8 hours a day. This is my "prototype" first project and is a full learning curve for me as i cant devote more than 2 or so hours to learning unity a day an have to keep several other IDE's and languages in my memory for "my day job". (problematic when you're interchanging ASP.net, PHP, javascript and C# on the fly)

I do thank you for taking the time to respond to my post as it has been insightful with regards to components vs game objects.(will research more)  I am not attacking you or NGUI, however i don't condone you passing judgement on me with zero background knowledge.

(I only post to forums when Google has failed me and or when i need a fresh set of eyes to spot something I've obviously missed but cant see, so know that i googled the hell out of this before posting here, much like my current problem with artifacts in transparency .png's and .tga's - not the white fringe issue)

Nicki

  • Global Moderator
  • Hero Member
  • *****
  • Thank You
  • -Given: 33
  • -Receive: 141
  • Posts: 1,768
    • View Profile
Re: TweenAlpha and UIPanel Help needed
« Reply #3 on: August 25, 2013, 01:45:25 PM »
If you do inspector changes it's always good practice to save the scene and save the project or it might not stick.