I am making a prefab that can change the player stats of my player from a script. Yet i want to be able to change the stat that I’m affecting from the inspector. Is there any way to do that?
The method told by ShadyProductions is great but if your health variable is private and don’t wish it to make public you can use this method.
Create a method in the original Prefab script let’s say
public void ChangeVariable(float newVariable) {
Variable = newVariable;
}
Then in the other script create a new variable (which will be seen in the inspector) let’s say its name is Health
Then use GetComponent to get reference of your first script like this
public float Health;
void Start () {
PreviousScript player = GetComponent<PreviousScript>();
player.ChangeVariable(Health);
}