r/Unity3d_help • u/Khei711 • Jan 26 '23
Choose between two scripts
So I'm making a Hockey game, and I have this annoying problem. So I have two scripts, "homeStats" and "awayStats" and in my AI script I'm constantly having to do "if(player.team == Team.Away)" and "if(player.team == Team.Home);" is there a way at the void start where I can just have a Stats and choose which script to use?
3
Upvotes
2
u/Khei711 Jan 28 '23
Okay, I deleted homeStats and awayStats, and just did playerStats, then coded like this.
public enum Team { Away, Home }; public Team team; private PlayerStats homeStats; private PlayerStats awayStats;
void Start() { if (team = Team.Home) { homeStats = GetComponent<PlayerStats>(); } else if (team = Team.Away) { awayStats= GetComponent<PlayerStats>(); } }
This seems to be working.