Tasharen Entertainment Forum

Support => NGUI 3 Support => Topic started by: beforethelight on December 24, 2012, 07:59:37 PM

Title: Create new widget
Post by: beforethelight on December 24, 2012, 07:59:37 PM
I have been searching here and on Unity forums but cannot find a answer.  I am trying to create a radar system and to do this I have to create new widgets as objects are created.  I have read this post http://www.tasharen.com/forum/index.php?topic=81.msg374#msg374 (http://www.tasharen.com/forum/index.php?topic=81.msg374#msg374) and cannot get it to work.  Everything I try gives me this error.  Assets/Standard Assets (Mobile)/Scripts/NGUIScripts/Test/Test.js(4,41): BCE0164: Cannot infer generic arguments for method 'NGUITools.AddWidget.<T>(UnityEngine.GameObject)'. Provide stronger type information through arguments, or explicitly state the generic arguments.  and my code has varied but the simplest being
  1. var label : UILabel = NGUITools.AddWidget<UILabel>(gameObject);
Title: Re: Create new widget
Post by: ArenMook on December 24, 2012, 08:25:56 PM
You're using C# code in a javascript file. I don't know javascript, but I believe the syntax for templated functions is quite different, and doesn't use angular brackets.
Title: Re: Create new widget
Post by: beforethelight on December 24, 2012, 08:53:01 PM
Sorry about that I figured it would work like the generic functions in unity.
Quote
These are known as generic functions. The significance they have for scripting is that you get to specify the types of parameters and/or the return type when you call the function. In JavaScript, this can be used to get around the limitations of dynamic typing:-

// The type is correctly inferred since it is defined in the function call.
var obj = GetComponent.<Rigidbody>();

and that does appear to be angular brackets...humm

But thanks for the help.