Changing Actor (Player) Name to a Public String with Button Click
Posted: Tue Dec 20, 2022 5:10 pm
My player changes their name on an Input Field in the Character Creation screen, where it's stored as a public string "nameOfPlayer", and saved on clicking the Continue button. The name displays below the player, but I want to change the actor name as well so it shows up in the conversation UI and possibly in conversation text.
This is the code I've been trying to make work, mainly based on very old forum posts from here;
But it's not working for me, and perhaps there's an easier way to set the actor name to my "nameOfPlayer" string?
This script above is attached to the Dialogue Manager and "SetOverrideName" doesn't show as an option when I try to apply it to the Continue button.
Thanks for any help!
This is the code I've been trying to make work, mainly based on very old forum posts from here;
Code: Select all
void Start() {
Lua.RegisterFunction("SetOverrideName", null, SymbolExtensions.GetMethodInfo(() => SetOverrideName(string.Empty, string.Empty)));
}
public static void SetOverrideName(string Tarul, string nameOfPlayer)
{
var go = GameObject.Find("Tarul"); //Tarul is the name of the player game object
nameOfPlayer = go.GetComponent<PlayerName>().nameOfPlayer; //Getting my player's name from a script on the player
if (go == null) return;
var overrideActorName = go.GetComponent<OverrideActorName>() ?? go.AddComponent<OverrideActorName>();
overrideActorName.overrideName = nameOfPlayer;
}
This script above is attached to the Dialogue Manager and "SetOverrideName" doesn't show as an option when I try to apply it to the Continue button.
Thanks for any help!