so i have a Scriptable Object with info about an Ability, note the OptionToggle
public class AbilityData : ScriptableObject
{
public bool OptionToggle;
//other info
}
i then have an Interface with some generic methods for the Ability Executioner Script to use
public interface IActivableAbility
{
public void Activate();
public void Deactivate();
}
and then i have the actual Ability Script with a reference to the ScriptableObject and its info
public class Ability1 : MonoBehaviour, IActivableAbility
{
public AbilityData abilityInfo;
public void Activate()
{
//ability code here
}
public void Deactivate()
{
//ability code here
}
and this is the Ability Executioner Script. how can i access the OptionToggle in the ScriptableObject from here?
public class SoulExecuter : MonoBehaviour
{
public IActivableAbility ability; // here i plug the Ability1 script
void Update()
{
if(Input)
{
ability.Activate();
}
else
{
ability.Deactivate();
}
}
}
is there a better way to implement an ability system like this?
Yes, there is a better way to implement an ability system like this in Unity. To access the OptionToggle property of the AbilityData ScriptableObject from your SoulExecuter script, you can use the following code:
public class SoulExecuter : MonoBehaviour
{
public IActivableAbility ability;
void Update()
{
if (Input)
{
// Access the OptionToggle property of the AbilityData ScriptableObject
// through the abilityInfo property of the Ability1 script
bool optionToggle = ability.abilityInfo.OptionToggle;
ability.Activate();
}
else
{
ability.Deactivate();
}
}
}
This is just one way to access the OptionToggle property of the AbilityData ScriptableObject from your SoulExecuter script. There are many other ways you can do this, depending on your specific requirements and preferences.
One thing you could consider doing is creating a SoulExecuter script that takes an AbilityData ScriptableObject as a parameter, like this:
public class SoulExecuter : MonoBehaviour
{
public AbilityData abilityData;
void Update()
{
if (Input)
{
// Access the OptionToggle property of the AbilityData ScriptableObject
bool optionToggle = abilityData.OptionToggle;
// Call the Activate method on the IActivableAbility interface
abilityData.Activate();
}
else
{
// Call the Deactivate method on the IActivableAbility interface
abilityData.Deactivate();
}
}