I created a method that simulates fire movement. This movement gets triggered from an external script but my problem is that I cannot start this method outside of Update. I need to call and start this method on Start because it’s too expensive to run this in each frame, and the Instantiate is too fast -it should instantiate slowly. The problem is that on Start doesn’t run.
Is there any way to run this method on start?
Here’s my sample code.
[HideInInspector] public bool isMoving; // State variable that checks if the fire isMoving
public GameObject fire; // the var that holds teh fire object
[SerializeField] private float speed; // fire speed
private void Update() {
FireMoveCheck();
}
private void FireMoveCheck() {
if (isMoving) {
Invoke(nameof(MovingFire), 2);
}
else if (isMoving == false) {
CancelInvoke();
}
}
private void MovingFire() {
var degrees = 0;
degrees = GetCompassInput(degrees);
gameObject.transform.position = transform.TransformPoint(speed / 3600, speed / 3600, 0);
gameObject.transform.rotation = Quaternion.Euler(-90, 0, degrees + 45);
var position = gameObject.transform.position;
var rotation = gameObject.transform.rotation;
Instantiate(fire, position, rotation);
}