When i debug it before disabling gameobject, its ok, but when i disable and enable and trying to jump, in original scripts it shows right number of space pressing, in second scripts only 1/5 or less goes true(p.s also tried fixed upd)
public bool jump = false;
void Update () {
horizontalMove = Input.GetAxisRaw("Horizontal") * runSpeed;
if (Input.GetButtonDown("Jump"))
{
jump = true;
}
Debug.Log(jump+"1");
}
void FixedUpdate()
{
controller.Move(horizontalMove * Time.deltaTime ,false,jump);
jump = false;
}
another script
public PlayerMovement playerMovement;
void Update()
{
isJumping = playerMovement.jump;
Debug.Log(isJumping);
}
For the life of me I can’t see what you are trying to achieve with this script. But your mistake is quite simple. You set your “jump” bool to true in Update and to false in FixedUpdate. You rely on your PlayerMovement script Update to happen after your first script Update, or between first script Update and FixedUpdate.
I can’t say if you will understand my previous sentence (I don’t think I can) so I will skip the details now and just point out the mistake: you rely on script execution order to be exactly the way you want. Never ever do that. Like ever, in 99,99% cases there is a better way.
From the get go, I would say that you should create an event and call it every time you press space. Then from other scripts you just subscribe to this event and your functions will be called whenever you invoke the event aka press space