View Single Post
  #6  
Old 08-01-2011, 09:44 PM
41Sqn_Banks 41Sqn_Banks is offline
Approved Member
 
Join Date: Oct 2007
Posts: 644
Default

You can always cast from AiAircraft to AiActor but you can not always cast from AiActor to AiAircraft.

You can check if its possible to cast from AiActor to AiAircraft by this:

Code:
AiActor actor;
if( actor is AiAircraft )
{
    AiAircraft aircraft = actor as AiAircraft;
    ...
}
If the "as" operator fails it returns null. This can be checked by
Code:
AiAircraft aircraft = actor as AiAircraft;
if(aircraft != null)
{
   ...
}
Of course its not necessary to check the success of the "as" operator if the "is" operator was successful.
Reply With Quote