Hi,
When you register a method with Lua, it's globally accessible. You can't register GetIsFollowing() on an NPC named Ann and then try to register the same function name on an NPC named Bob.
Here are two possible solutions:
1. Include the NPC's name in the Lua function name:
Code: Select all
Lua.RegisterFunction($"Is{name}Following", this, SymbolExtensions.GetMethodInfo(() => GetIsFollowing()));
If you put the script on a GameObject named "Ann", it will add a function named IsAnnFollowing().
If you put the script on a GameObject named "Bob", it will add a function named IsBobFollowing().
---
2. Or write a single method that accepts a GameObject name:
Code: Select all
public bool GetIsFollowing(string gameObjectName)
{
return GameObject.Find(gameObjectName).GetComponent<YourScript>().isFollowing;
// (Note: You should check if GameObject.Find and GetComponent return null.)
}
Lua.RegisterFunction($"IsFollowing", this, SymbolExtensions.GetMethodInfo(() => GetIsFollowing(string.Empty)));