Up to now, the NPC prefab didn’t have any scripting attached to it. Everything was done via the MapManager. Let’s change that, in the interest of future code sanity and flexibility.
We’ll attach a script to the prefab and call it NpcScript:
For now, all it does it wait for newPosition or newScale to be altered, and then moves to the new position/scale over the next two seconds.
(Note: I had to add the two “hmm” lines because the two Vector3s were getting close but never close enough. Surprising behavior from Slerp;
I had assumed that once t exceeded 1, the returned Vector3 would be equal to b.)
But this won’t do anything as long as MapManager is directly changing the position and localScale of the Npc transform, so we make changes like this:
It’s a little kludgy right now, but does it work?
Separation Anxiety, Part One
We still want a central manager for NPCs, so we’ll split out from MapManager and make NpcManager.
Not a lot of actual code change, just separation, but something to point out: Each manager has an UpdateZ method; the one in mapManager calls the one in npcManager.