[UE4]為UStaticMeshComponent添加點擊事件


BlockMesh->OnClicked.AddDynamic(this, &APuzzleBlock::BlockClicked);   //鼠標點擊事件
BlockMesh->OnInputTouchBegin.AddDynamic(this, &APuzzleBlock::OnFingerPressedBlock);   //觸摸屏點擊事件

void APuzzleBlock::BlockClicked(UPrimitiveComponent* ClickedComp)
{
    bIsActive = !bIsActive; // flip the value of bIsActive
                            // (if it was true, it becomes false, or vice versa)
    if (bIsActive)
    {
        BlockMesh->SetMaterial(0, OrangeMaterial);
    }
    else
    {
        BlockMesh->SetMaterial(0, BlueMaterial);
    }
    // Tell the Grid
    if (OwningGrid != NULL)
    {
        OwningGrid->AddScore();
    }
    // --TO HERE--
}


void APuzzleBlock::OnFingerPressedBlock(ETouchIndex::Type FingerIndex, UPrimitiveComponent* TouchedComponent)
{
    BlockClicked(TouchedComponent);
}

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM