'Create a Scriptable Object In Game
I am trying to make an app where the user can create a new player and enter some data about its sports performances. To do that, I created a Scriptabe Object Class "Players" with (for the moment) only a name. I would like to be able to create/instantiate a new player when clicking on a "Add new Player" Button. How can I create a new ScriptableObject in Game and define its name?
Solution 1:[1]
You can create a simple void that gets called whenever you click a button. Something like this:
public void AddNewPlayer() {
new Player();
}
Because you want to give the player a name you can just pass the name in as a parameter.
Your Player Object could look like this:
class Player {
String name;
public Player(String name) {
this.name = name;
}
}
If you want the player to put in their own name you can do this with an input field.
And then in the AddNewPlayer function you just read the input of the inputField and use this as the name.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | GetMyIsland |
