get variable from scriptableObject
Hey! I am making a game that involves a dynamic fighting system with the user choosing what (magic) attack in which slot so I thought about using scriptableObjects as data holders for the different attacks.
So I want to access a variable of a scriptableObject that looks like this:
using UnityEngine;
using System.Collections;
[CreateAssetMenu(menuName = "Magic Attack")]
public class magicAttack_01 : ScriptableObject {
public GameObject Attack;
public int ThrowForce;
public int damage;
}
So let's say I make a scriptableObject that holds the functions for using those attacks. using UnityEngine; using System.Collections;
public class MagicAttackFunctions : ScriptableObject {
void FireAttack(Transform Launchpoint, ScriptableObject dataFile){
//get variables from dataFile
GameObject FiredAttack = Instantiate([Attack variable from dataFile], Launchpoint.transform.position, Launchpoint.transform.rotation);
FiredAttack.GetComponent<Rigidbody>().AddForce(Launchpoint.forward * [ThrowForce]);
}
}
And the enemy has a script that subtracts the damage from its health onCollisionEnter. Please help me, how can I dynamically get the variables from the scriptableObjects?
Thank you in advance, Real20Games
Your answer
![](https://koobas.hobune.stream/wayback/20220612092817im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
How do I access variables from Scriptable Objects in an array? 0 Answers
Does loading a ScriptableObject on runtime and modifying it affect the ScriptableObject in file? 1 Answer
Having Trouble Disabling Script Components. 1 Answer
ScriptableObject not saving to Asset properly 0 Answers
Attaching method to scriptableobject 1 Answer