在学习如下虚幻引擎开门案例时,代码报错
USceneComponent::RelativeRotation成员是私有的无法访问
最简单的 UE 4 C++ 教程 ——通过插值和重叠事件实现开门效果【三十一】_panda1234lee的博客-CSDN博客_ue4插值使用
解决方案如下:
// Called every frame
void AOpenDoorWithLerp::Tick(float DeltaTime)
{
Super::Tick(DeltaTime);
// 报错:访问private成员
//DoorRotation = Door->RelativeRotation;
// 用函数才能访问 直接访问这个成员是 私有的
DoorRotation = Door->GetRelativeRotation();
if (Open)
{
Door->SetRelativeRotation(FMath::Lerp(FQuat(DoorRotation), FQuat(FRotator(0.0f, RotateValue, 0.0f)), 0.01f));
}
else
{
Door->SetRelativeRotation(FMath::Lerp(FQuat(DoorRotation), FQuat(FRotator(0.0f, 0.0f, 0.0f)), 0.01f));
}
}