주기적으로 나타났다가 사라지는 플랫폼은 장애물 코스 같은 플랫폼 게임 모드의 필수 요소입니다. 여기서는 플레이어가 점프 타이밍을 잘 계산해서 다음 플랫폼으로 나아가야 합니다. 실수하면 바닥으로 떨어져서 다시 도전합니다.
이 예시에서는 씬 그래프 및 Verse로 제작된 컴포넌트를 사용하여 사라지는 플랫폼을 만드는 방법을 보여줍니다. 루프로 사라지는 플랫폼에서 동일한 개념의 Verse로 제작된 장치 구현과 비교해 보세요.
플랫폼을 사라지게 만들기
씬 그래프를 사용하여 사라지는 플랫폼을 만들려면 다음 단계를 따릅니다.
씬에 DisappearingPlatform으로 명명한 엔티티를 추가합니다. 씬에 엔티티 및 컴포넌트를 추가하는 과정에 대해 자세히 알아보려면 엔티티 및 컴포넌트 작업하기를 참고하세요.
사라지는 플랫폼 엔티티에 mesh_component를 추가하고 메시를 큐브(cube)로 설정합니다.
disappear_on_loop_component로 명명한 새 Verse 컴포넌트를 생성한 후 이 컴포넌트를 사라지는 플랫폼 엔티티에 추가하고 엔티티를 저장합니다. 자신만의 컴포넌트를 만드는 방법에 대해 알아보려면 Verse를 사용하여 자신만의 컴포넌트 만들기를 참고하세요.VS Code에서
disappear_on_loop_component를 열어 다음 단계를 따라 편집합니다.Duration으로 명명된 컴포넌트에 편집 가능한float프로퍼티를 추가합니다. 이는 플랫폼이 숨겨지기 전에 표시되어야 하는 시간과 다시 나타나기 전에 숨겨져 있어야 하는 시간을 결정합니다.Verseusing { /Verse.org } using { /Verse.org/Native } using { /Verse.org/Simulation } using { /Verse.org/SceneGraph } # Loops between hiding and showing the entity by enabling and disabling # its static mesh and collision components. disappear_on_loop_component := class(component):플랫폼을 숨기려면 콜리전을 비활성화하여 스태틱 메시가 보이지 않도록 함으로써 플레이어가 플랫폼에 착지할 수 없도록 합니다.
Hide()로 명명한엔티티에서 확장된 새 함수를disappear_on_loop_component클래스에 추가합니다. 이 함수 내부에서 원하는 타입으로GetComponents[]를 호출하여(여기에는mesh_component) 엔티티의 스태틱 메시를 반환합니다. 그런 다음 스태틱 메시에서Disable()을 호출합니다.Verse# If the entity has a mesh or collision component, disable them. (Entity:entity).Hide():void= if: StaticMesh := Entity.GetComponent[mesh_component] then: StaticMesh.Disable()disappear_on_loop_component클래스에 다른엔티티확장 함수를 추가하고Show()로 명명합니다.Hide()와 동일한 방식으로 구현하지만, 스태틱 메시 컴포넌트에서 대신Enable()을 호출합니다.Verse# If the entity has a mesh or collision component, enable them. (Entity:entity).Show():void= if: StaticMesh := Entity.GetComponent[mesh_component] then: StaticMesh.Enable()마지막으로
OnSimulate()에서루프표현식을 사용하여 플랫폼이 숨겨졌다가 나타나는 것을 반복하도록 하고, 반복 시Sleep()을 호출합니다. 완성된disappear_on_loop_component클래스는 다음과 같습니다.Verseusing { /Verse.org } using { /Verse.org/Native } using { /Verse.org/Simulation } using { /Verse.org/SceneGraph } # Loops between hiding and showing the entity by enabling and disabling # its static mesh and collision components. disappear_on_loop_component := class<final_super>(component):저장하고 코드를 컴파일합니다.
UEFN 아웃라이너에서 DisappearingPlatform 엔티티를 disappearing_platform_prefab으로 명명된 프리팹으로 승격합니다. 프리팹으로 승격하면, 나중에 필요한 경우 사라지는 플랫폼의 더 많은 인스턴스를 생성하고 룩과 베이스 구현을 업데이트할 수 있습니다. 엔티티를 프리팹으로 승격하는 방법은 프리팹 및 프리팹 인스턴스를 참고하세요.
전체 스크립트
이 섹션에서 사용된 완성된 코드는 다음과 같습니다.
disappear_on_loop_component.verse
using { /Verse.org }
using { /Verse.org/Native }
using { /Verse.org/Simulation }
using { /Verse.org/SceneGraph }
# Loops between hiding and showing the entity by enabling and disabling
# its static mesh and collision components.
disappear_on_loop_component := class<final_super>(component):