i have a script that disables another scripts when i press a button that has “transform.position = Vector3.MoveTowards …” and activates another objects scrpitc. Activating and disaclebing works fine but ater disable this scritp that has “transform.position = Vector3.MoveTowards…” line the object it moves stop becousr script is disabled. How can i disable that script after it finishes its moves.?
You can use events to trigger things, then just listen for those events in another class, or the same class:
System.Action SomethingHappened;
if (SomethingHappened != null) { SomethingHappened(); }
You would put this at the end of your logic that determines when the object has actually finished its objective. You will need to do a check to see that the object is at the position you want, don’t do a position == vector check, it won’t work. Do a distance check with a range that you consider ok.
I realized I should add a little more to help you out with this (put something like this at the end of your update):
public System.Action FinishedMovement;
float threshold = 0.1f;
void Update() {
// Blah blah tranform.position.MoveToward(blahblah)
if (Vector3.Distance(targetVector, transform.position) <= threshold) {
if (FinishedMovement != null) { FinishedMovement(); }
}
}