I need to add a delay to a wholle script on all of its void Update ()
Not sure the best way to tackle this option one
Fixed update()
This option I cant see a way to set time like once every 5 frames
Add a Coroutines
This option I cant see a way to call it for the whole update just per function.
Basically I need my badguys to update like once every 10th of a second not every frame as its just to much info going back and forth. any suggestions on how to do this will be greatly appreciated.
Eric thanks for response can you explain a little more in details. As I am a artist not a coder so need a little more of a nudge in right direction. like something like this?
void Update ()
{
InvokeRepeating(, 2, 0.3);
Vector3 movement = Vector3.zero;
if (isPlayer) {
if (!dead) {
movement = MovePlayer ();
} else {
(ect)
That would be very bad to call InvokeRepeating every frame. Maybe not right away but you’ll likely notice a serious performance bottleneck after a period of time.
You’ll probably want to call that function in Start, OnEnable (followed by a cancel Invoke with OnDisable), or OnBecameVisible depending on your needs.
It seems like you need the function to execute right away and assuming you are not disabling your component (or if you do but have no further need for the repeating logic if the component is re-enabled), having your InvokeRepeating call on Start() should be enough.
SteveJ beat me to it, but I’ll post this as a double-confirm XD
Edit: Actually I’ll add onto this.
@OP You said you can only see this used per function and not Update, but you can add a function call to Update in addition to code within the update or just completely migrate all of your code out of Update into a function call and call it the function with the migrated logic from Update.
Also, unless you’re doing refined movement or something that absolutely must match the framerate of the screen, you probably don’t need to do it in Update and can use Invokes, Coroutines and/or Events/Delegates to perform logic.