How to implement automatic ingame script rewriting
Hi, Is it possible to have the script of a Gameobject's component automatically rewritten during the game ? For example, a unit is at place A and its component's script contains the path to go to place B. Once B is reached by the unit, the script is replaced by another script that contains the path to go to C. Thanks.
Answer by Tobychappell · Jul 07, 2018 at 09:04 AM
You could remove the component that moves the game object from A to B when it reaches B and then Add the second script that moves the game object from B to c using
Destroy(scriptA) ;
gameobject.AddComponent(typeof(ScrpitBClassName));
However if you're going to be recycling these id just enable one and disable the other.
Or better yet have instances of both classes that derive from a base class with virtual methods and switch bewteen the current instance like a simple state machine.
Your answer
Follow this Question
Related Questions
Player not moving in the right direction instantly 1 Answer
Weapon Reload script error 0 Answers
How Asus xtion2 is used in Unity 0 Answers
2019.3 game foundation save 0 Answers