码迷,mamicode.com
首页 > 其他好文 > 详细

控制鼠标单击的物体

时间:2017-03-16 20:19:50      阅读:208      评论:0      收藏:0      [点我收藏+]

标签:get   result   ast   eth   color   const   false   cto   vector   

控制鼠标单击的物体 

void AMyCharacter::PossesClicked()  
{  
    APlayerController* PlayerController = Cast<APlayerController>(GetController());  
    if (PlayerController != nullptr)  
    {  
        // Get the coordinates of the mouse from our controller  
        float LocationX;  
        float LocationY;  
        PlayerController->GetMousePosition(LocationX, LocationY);  
        // Do a trace and see if there the position intersects something in the world  
        FVector2D MousePosition(LocationX, LocationY);  
        FHitResult HitResult;         
        const bool bTraceComplex = false;  
        if (PlayerController->GetHitResultAtScreenPosition(MousePosition, ECC_Visibility, bTraceComplex, HitResult) == true )  
        {  
            // If the actor we intersected with is a controller posses it  
            APawn* ClickedPawn = Cast<APawn>(HitResult.GetActor());  
            if( ClickedPawn != nullptr )  
            {  
                // Unposses ourselves  
                PlayerController->UnPossess();  
                // Posses the controller we clicked on  
                PlayerController->Possess(ClickedPawn);  
            }  
        }  

    }  
}  

 

控制鼠标单击的物体

标签:get   result   ast   eth   color   const   false   cto   vector   

原文地址:http://www.cnblogs.com/hanliu/p/6561092.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!