I have a script which looks like this.
public class Script1: MonoBehaviour
{
public Image Character;
}
I have another script which tries to access the Image like so.
public class Script2: MonoBehaviour
{
Script1.Character.sprite = Sprite1;
}
Of course I get an error because Character is a non-static object. My question is how do I change the sprite in Script1 from Script 2? From what I've read the best way is to define a gameobject in Script2 that references Script1 or use getters/setters. I'm only a couple months into learning C# however and I've never used either of those methods, and every reference I've read doesn't explain it in a way that makes sense to me.
Specifically, if I define a gameobject from Script2, will it create a new gameobject or will it alter the existing one?
public Image Character needs to be accessible to more than one other script eventually, so whatever method I use I need to make sure I'm altering Script 1 rather than creating a new object, or at least it needs to have the same effect.
Could anyone please help with a simple solution?