Sunday, 17 March 2013

Scripting Material Instances


class UDNPawn extends UTPawn;

var MaterialInstanceConstant NewMIC;

simulated function PostBeginPlay()
{
       Super.PostBeginPlay();

        InitMaterialInstance();
}

function InitMaterialInstance()
{
           Mesh.CreateAndSetMaterialInstanceConstant(1);
           Mesh.SetMaterial(1, NewMIC);
}

function UpdateMaterialInstance(float tValue)
{
              NewMIC.SetScalarParameterValue('HealthBar', tValue);
}

simulated event TakeDamage(int Damage, Controller InstigatedBy, vector HitLocation, vector Momentum,  
     class<DamageType> DamageType, optional TraceHitInfo HitInfo, optional Actor DamageCauser)
{
       Super.TakeDamage(Damage, InstigatedBy, HitLocation, Momentum, DamageType, HitInfo,
              DamageCauser);
       UpdateMaterialInstance(Health);
}

defaultproperties
{
        NewMIC=MaterialInstanceConstant'AlphaOneMay.Materials.FuchikomaMat_INST'
     
}