[Input][Interaction] Add interactable items
This commit is contained in:
50
Assets/Scripts/LevelSwitch.cs
Normal file
50
Assets/Scripts/LevelSwitch.cs
Normal file
@@ -0,0 +1,50 @@
|
||||
using UnityEngine;
|
||||
|
||||
public class LevelSwitch : MonoBehaviour
|
||||
{
|
||||
public LevelSwitchData switchData;
|
||||
public SpriteRenderer iconRenderer;
|
||||
private Interactable interactable;
|
||||
|
||||
void Awake()
|
||||
{
|
||||
interactable = GetComponent<Interactable>();
|
||||
if (interactable != null)
|
||||
{
|
||||
interactable.Interacted += OnInteracted;
|
||||
}
|
||||
ApplySwitchData();
|
||||
}
|
||||
|
||||
void OnDestroy()
|
||||
{
|
||||
if (interactable != null)
|
||||
{
|
||||
interactable.Interacted -= OnInteracted;
|
||||
}
|
||||
}
|
||||
|
||||
#if UNITY_EDITOR
|
||||
void OnValidate()
|
||||
{
|
||||
ApplySwitchData();
|
||||
}
|
||||
#endif
|
||||
|
||||
public void ApplySwitchData()
|
||||
{
|
||||
if (switchData != null)
|
||||
{
|
||||
if (iconRenderer != null)
|
||||
iconRenderer.sprite = switchData.mapSprite;
|
||||
gameObject.name = switchData.targetLevelSceneName;
|
||||
// Optionally update other fields, e.g. description
|
||||
}
|
||||
}
|
||||
|
||||
private void OnInteracted()
|
||||
{
|
||||
Debug.Log($"LevelSwitch.OnInteracted: Switching to level {switchData?.targetLevelSceneName}");
|
||||
// TODO: Add scene loading logic here, e.g. UnityEngine.SceneManagement.SceneManager.LoadScene(switchData.targetLevelSceneName);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user