0

私は、その場で作成する必要があるいくつかのプロジェクトに取り組んでいます。NGUI を使用したボタンです。いくつかの答えが見つかりましたが、どれも役に立ちませんでした。簡単だと思いますが、http ://www.tasharen.com/forum/index.php?topic=81.0 と NGUI スクリプト (UICreateWidgetWizard.cs) で見つけたものによると、次のようになります。

            UILabel lbl = NGUITools.AddWidget<UILabel>(go);

それはまだ機能していません..

私のコードは次のとおりです。

            UIButton button =  NGUITools.AddWidget<UIButton>(parent);

みんな助けてくれてありがとう!

4

2 に答える 2

1

@pfranzaが示唆するように、スクリプトでパブリックオブジェクトとして参照できるUIButtonのプレハブを作成し、それを作成するには

GameObject newButton = NGUITools.AddChild(mParentGameObject, mButtonPrefab);

または、必要に応じて実行時に完全に作成することもできます。

    UISprite mButtonSprite = NGUITools.AddSprite(mParentGameObject, mAtlas, "Button");
    //Button is the name of the sprite in the atlas

    mButtonSprite.MakePixelPerfect();
    NGUITools.AddWidgetCollider(mButtonSprite.gameObject);
    mButtonSprite.gameObject.AddComponent<UIButton>();
    //add any further components/set up you like.
于 2014-09-05T09:49:25.913 に答える