← Back to all addons

Secret Door Interactable

Posted by Mr.Titan on Sep 28, 2024 at 7:23 PM

ExperimentalFeature
šŸ’” 7 šŸ˜€ 1

Allows you to interact with secret doors, but in fact, it’s much more then that. I use simillar systems to interact with torches and candles, secret doors and cracks on the walls and floor.

For context, in my example, i want a crack in the wall that if you have the ability (slash), it will allow you to transform into a secret door. This should play a sound, change sprite (in my case animation) and enable teleport, plus changes the flag in your save.

I’ll be posting in the comments too, because its too long.

Actions States - All action states that allows you to manage you operations based on the result of the interaction

Assets/Mythril2D/Core/Runtime/Scripts/Utils/EObjectAction.cs

using System;

namespace Gyvr.Mythril2D
{
    [Serializable]
    public enum EObjectAction
    {
        Switch,
        Activate,
        Deactivate
    }
}

Object Interation Command - To call custom operations in your objects when interact with.

If you extend this class, it will allow you to perform action has a interactable.

Assets/Mythril2D/Core/Runtime/Scripts/Commands/ObjectInteration.cs

using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;


namespace Gyvr.Mythril2D
{

    // Interface for light-specific behavior
    public interface IObjectAction
    {
        void SetState(EObjectAction state);
    }

    [Serializable]
    public class ObjectInteration : ICommand
    {
        [SerializeField] private GameObject m_object_action;
        [SerializeField] private EObjectAction m_action = EObjectAction.Switch;

        //Executes the custom function of the target object class that contains "IObjectAction" interface
        public void Execute()
        {
            IObjectAction actionObject = m_object_action.GetComponent<IObjectAction>();
            Debug.Assert(actionObject != null);
            actionObject.SetState(m_action);
        }
    }
}

šŸ’¬ Comments (2)

BellBlitzKing Sep 28, 2024 at 08:24 PM
I’m waiting for that armors & custom gear code! šŸ˜
šŸ‘ 1
Mr.Titan Sep 29, 2024 at 07:13 PM
I’ll be looking at that, since it requires some review. But now that i see you guys want it so bad, i’ll check on that.
ā¤ļø 1

Want to continue the conversation?