求助unrealscript问题
Here is an example of the state concepts discussed so far:
// This is the automatic state to execute.
auto state Idle
{
// When touched by another actor...
function Touch( actor Other )
{
log( "I was touched, so I'm going to Attacking" );
GotoState( 'Attacking' );
Log( "I have gone to the Attacking state" );
}
Begin:
log( "I am idle..." );
sleep( 10 );
goto 'Begin';
}
// Attacking state.
state Attacking
{
Begin:
Log( "I am executing the attacking state code" );
//...
}
When you run this program and then go touch the actor, you will see:
I am idle...
I am idle...
I am idle...
I was touched, so I'm going to Attacking
I have gone to the Attacking state
I am executing the attacking state code
Make sure you understand this important aspect of GotoState: When you call GotoState from within a function, it does not go to the destination immediately, rather it goes there once execution returns back to the state code.
这里面不是说状态应该直接跳转到下一个状态么?为什么还会运行Log( "I have gone to the Attacking state" );
[解决办法]
因为这个GotoState是在function中调用的,因此它会执行完所有的state code之后再跳转到Attacking state中去执行;而如果你在state code中调用GotoState,它便会立刻跳转。