Pastebin

Paste #1094: FlyingHUD.uc

< previous paste - next paste>

Pasted by tdn

Download View as text

class FlyingHUD extends HUD;

var UIScene HUDScene;

var MaterialInstanceConstant lifeMaterial;
var UILabel MyLabel;
var UIObject MyObject; //All widgets has this base class

function PostBeginPlay()
{
    local UIInteraction UIController;
    local FlyingController MyPC;
    local int idx;
    local array< UIObject > HUDChildren;
    local MaterialInterface mat;

    super.PostBeginPlay();

    MyPC = FlyingController(PlayerOwner);

    UIController = MyPC.GetUIController();
    if( UIController != none )
    {
        //Open the scene
        UIController.OpenScene( UIScene'KatamaHUD.Scenes.ui_scene_1', LocalPlayer( MyPC.Player ), HUDScene );

        //Loop trough all the widgets and create references to them
        HUDChildren = HUDScene.GetChildren(true);
        for( idx = 0; idx < HUDChildren.length; idx++ )
        {

            if(HUDChildren[idx].Name == 'UILabel_0')
            {

            }

            if( HUDChildren[ idx ].Name == 'lifebar' ) //'lifebar' references the name of the widget in the UIScene
            {
                //Get the widgets material
                mat = MaterialInterface(UIImage(HUDChildren[idx]).ImageComponent.ImageRef.GetSurface());

                //Create a new MaterialInstanceConstant
                lifeMaterial = new() class'MaterialInstanceConstant';

                //Set a reference to the widget material
                lifeMaterial.SetParent( mat );

                //Replace the widget material with the MaterialInstanceConstant so we can modify it
                //UIImage(HUDChildren[idx]).ImageComponent.SetImage(Minimap_material);
            }

            if( HUDChildren[ idx ].Name == 'my_label' )
            {
                MyLabel = UILabel(HUDChildren[ idx ]);
            }

            if( HUDChildren[ idx ].Name == 'my_widget' )
            {
                MyObject = HUDChildren[ idx ];
            }
        }
    }
}

event Tick( float DeltaTime )
{
    if(PlayerOwner.Pawn != none &&  lifeMaterial != none)
    {
        //The widget material has a scalar parameter called 'health'
        lifeMaterial.SetScalarParameterValue('health', PlayerOwner.Pawn.Health);
    }

    if(true)
    {
        MyLabel.SetValue("Thomas");
        MyLabel.SetVisibility(true);
        MyObject.SetVisibility(false);
    }
    else
    {
        MyLabel.SetVisibility(false);
        MyObject.SetVisibility(true);
    }
}

New Paste


Do not write anything in this field if you're a human.

Go to most recent paste.