MasterinUnrealScript
E:/udnweb/udn script/udn.epicgames.com/Three/MasteringUnrealScriptFunctionsCH.html #第六章 –函數
UC文件
MasterTest
classMasterTestextends simplegame;
AmbientCreatureNode
classAmbientCreatureNodeextendsInfo placeable;
var FloatRadius;
var()ConstEditConst DrawSphereComponentRadiusComponent;
functionPreBeginPlay()
{
Radius=RadiusComponent.SphereRadius;
Super.PreBeginPlay();
}
defaultproperties
{
BeginObjectClass=DrawSphereComponent Name=DrawSphere0
SphereColor=(B=255,G=70,R=64,A=255)
SphereRadius=48.000000
EndObject
RadiusComponent=DrawSphere0
Components.Add(DrawSphere0);
}
AmbientCreature_Fish
classAmbientCreature_Fishextends Actor
placeable;
var()array<AmbientCreatureNode>MyNodes;
var()floatSpeed;
functionPostBeginPlay()
{
Super.PostBeginPlay();
SetRandDest();
//`log(coerce string Msg, optional bool bCondition=true, optional nameLogTag='ScriptLog' );
}
functionSetRandDest()
{
localIntIdx;
localAmbientCreatureNodeDestNode;
localVectorMoveDirection;
Idx=Rand(MyNodes.Length);
`Log(Idx); //輸出變量的值到日誌
worldinfo.Game.Broadcast(self,Idx); //輸出變量的值到self的屏幕
//`Log("CustomController up控制類"); //輸出字符串:CustomController up 控制類
//worldinfo.Game.Broadcast(self,"Idx$編號"); //輸出字符串:Idx編號
//例如變量A=0.233,變量B='名字:',變量C="ABC",那麼可以這樣串接: Broadcast(self,A$"編號成員的"$B@C) 最後輸出的結果爲: 0.233編號成員的名字: ABC 注意:和ABC之間有個空格,因爲$是直接串接,@ 是加空格後串接
DestNode=MyNodes[Idx];
MoveDirection=DestNode.Location-Location;
Velocity=Normal(MoveDirection)*Speed;
SetTimer(5,false,'SetRandDest');
}
defaultproperties
{
Speed=170
BeginObjectClass=DynamicLightEnvironmentComponent Name=MyLightEnvironment
EndObject
LightEnvironment=MyLightEnvironment
Components(0)=MyLightEnvironment //組件不附加就不能使用,等於沒有定義組件,和Components.Add(MyStaticMesh)類似。“任何時候您使用某種類型的組件時,爲了使它們有效,都需要把它們分配給Components數組。”
BeginObjectClass=StaticMeshComponent Name=MyStaticMesh
StaticMesh=StaticMesh'Chapter_06_Functions.ClownFish'
Scale3D=(X=0.250000,Y=0.250000,Z=0.25000)//測試有效
LightEnvironment=MyLightEnvironment //註釋掉,靜態網格物體沒有光照--沒有光照的物體是什麼顏色??
EndObject
Components(1)=MyStaticMesh //註釋掉在場景中就看不到定義的網格物體了,和Components.Add(MyStaticMesh)類似
CollisionComponent=MyStaticMesh//啓用靜態網格物體自身的碰撞體,添加碰撞屬性後的靜態網格物體就可以和其它物體產生碰撞了
DisplayMesh=MyStaticMesh
bCollideWorld=true //添加碰撞屬性後的靜態網格物體就可以和其它物體產生碰撞了,有碰撞屬性的物體運動到一塊兒時就不會有穿插,雖然物體間有碰撞,但是和世界碰撞與否需單獨設置
Physics=PHYS_Projectile
bStatic=false
bMovable=true
}
NOTICE:
SetRandDest函數
DestNode在Editor中的設置,若不設置log會提示找不到DestNode
小結:
函數實現靜態網格物體簡單地直線運動
A:一個Actor自帶哪些基礎功能函數變量和信息(物理,碰撞,位置,旋轉,SetDrawScal,動態物體動態光照Move,變量修飾符,類的修飾符,
Function,PreBeginPlay,PostBeginPlay,Super,return,function變量類型,function(out變量類型),,,,,,,,,,,,,,
1. 理解Log在程序調試中的用處
2. 理解SetTimer()時間驅動函數
3. 一些Actor自帶的常用函數