Hi,
Can’t seem to find the answer, and I am surprised I am not able to find any answer about this.
The idea is simple : I would like to assign a c# script as a variable, and use it during runtime to do a AddComponent, to be able to do something like this :
[System.Serializable]
public class PowerUp
{
public string name;
public string description;
public Sprite thumbnail;
public Component script;
}
In this very specific scenario, a script manages a power up behaviour : adding it or removing it enables or disable the PowerUp. I suppose this is how The Binding Of Isaac manages the items ?
public void AddPowerUp (PowerUp p)
{
transform.AddComponent<p>();
}
Right now I am using a prefab system wich works fine but is less intuitive to work with, and creates uncessearry gameObjects (while one gameObject could hoold all the created components).
My understanding is that Component can only be assigned for scripts in gameObject. I also undestand that a limitation can be public variables in the script I want to assign (which I dont have).
Maybe I am missing a complete logic here. Does anyone have any clue ?
Cheers,