unirun1/Assets/Scripts/Platform.cs

33 lines
1022 B
C#
Raw Permalink Normal View History

2026-01-28 14:27:40 +00:00
using UnityEngine;
// 발판으로서 필요한 동작을 담은 스크립트
public class Platform : MonoBehaviour {
public GameObject[] obstacles; // 장애물 오브젝트들
private bool stepped = false; // 플레이어 캐릭터가 밟았었는가
// 컴포넌트가 활성화될때 마다 매번 실행되는 메서드
private void OnEnable() {
2026-01-29 02:32:06 +00:00
stepped = false;
2026-01-28 14:27:40 +00:00
// 발판을 리셋하는 처리
2026-01-29 02:32:06 +00:00
for(int i = 0; i < obstacles.Length;i++)
{
if(Random.Range(0,3) == 0)
{
obstacles[i].SetActive(true);
}
else
{
obstacles[i].SetActive(false);
}
}
2026-01-28 14:27:40 +00:00
}
void OnCollisionEnter2D(Collision2D collision) {
// 플레이어 캐릭터가 자신을 밟았을때 점수를 추가하는 처리
2026-01-29 02:32:06 +00:00
if(collision.collider.tag == "Player" && !stepped)
{
stepped = true;
GameManager.instance.AddScore(1);
}
2026-01-28 14:27:40 +00:00
}
}