HI there.
I have a parent class called Weapon(), which is non-instantiable. NormalWeapon() derives from it. Only NormalWeapon has charge. The code is this:
Weapon Update():
if (shootTrigger == true)
shootTrigger = false;
else if (InputController.GetKeyDown (Buttons.shoot))
shootTrigger = true;
That is, I want shootTrigger to be true only for a frame and NormalWeapon to get this info, so in
NormalWeapon Update() we have:
if (shootTrigger)
charging = true;
“charging” never happened to be true. So in Script Execution Order I put:
Weapon (100)
NormalWeapon (200)
Still, charging never happened to be true. NormalWeapon’s charging gets the true value only if I put the shootTrigger verification in NormalWeapon’s LateUpdate().
The impression I’m getting is this:
parent Update() executes
then children Update() executes
Even if this order is changed in the Project Settings???
Thank you!
You could just call a virtual function instead of trying to balance between false and true and getting mixed up.
Your “NormalWeapon” script derives from “Weapon” correct? Meaning the top of your NormalWeapon script it looks like this?
public class NormalWeapon : Weapon {
Why not just do this in weapon:
public class Weapon : MonoBehaviour {
bool shootTrigger = false;
void Update()
{
if (InputController.GetKeyDown(Buttons.shoot) && !shootTrigger) {
shootTrigger = true;
Shoot();
}
}
public virtual void Shoot()
{
}
}
and in your normal weapon script…
public class NormalWeapon: Weapon {
bool charge = false;
public override void Shoot()
{
charge = true;
shootTrigger = false;
}
}
Another thing too…GetButtonUp might work better for you. If you want the user to have to click each time shootTrigger = true, GetButtonUp waits until the button has been lifted. A button has 3 states… GetButton (called every frame the button is being held), GetButtonDown (Called the frame when the button is pressed) and GetButtonUp (called when the button is lifted). These have an order of their own by the nature of how a user is clicking the physical button, be it a key on a keyboard, mouse, touchscreen, nuclear missile launch button.
GetButtonDown → GetButton → GetButtonUp