ユーザ用ツール

サイト用ツール

wiki:ue4:tips:501

以前のリビジョンの文書です


C++/コンポーネントの追加(4.7.3)

  1. 「詳細パネル」の「新規コンポーネントの追加」から「新規C++コンポーネントの追加…」を選択する。
  2. 「ActorComponent」を選択して次へ進む。
  3. 「MyActorComponent」など名前を付けて「クラスを作成」する。
// MyActorComponent.h 
class STDPROJECT_API UMyActorComponent : public UActorComponent
{
    GENERATED_BODY()
 
private:
    // 追加
    float m_fRunningTime;
}
// 開始時に呼ばれる
void UMyActorComponent::InitializeComponent()
{
    Super::InitializeComponent();
}
 
 
// 毎フレーム呼ばれる
void UMyActorComponent::TickComponent( float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction )
{
    Super::TickComponent( DeltaTime, TickType, ThisTickFunction );
 
    // 追加
    AActor* pOwner = GetOwner();
    FVector NewLocation = pOwner->GetActorLocation();
    float DeltaHeight = (FMath::Cos(m_fRunningTime + DeltaTime) - FMath::Cos(m_fRunningTime));
    NewLocation.X += DeltaHeight * 20.0f;
    m_fRunningTime += DeltaTime;
    pOwner->SetActorLocation(NewLocation);
}
Permalink wiki/ue4/tips/501.1427536324.txt.gz · 最終更新: 2015/03/28 09:52 by step

oeffentlich