public override void GetInput() { if (isFinished || isRespawning) { horz = 0; vert = 0; return; } // drop out if we're not supposed to be controlling this player if (!canControl) { return; } // grab inputs from the default input provider horz = Mathf.Clamp(default_input.GetHorizontal(), -1, 1); vert = Mathf.Clamp(default_input.GetVertical(), -1, 1); // fire if we need to if (default_input.GetFire() && canFire) { // tell weapon controller to deal with firing weaponControl.Fire(); } }
public override void GetInput() { // calculate steering amount steer = Mathf.Clamp(default_input.GetHorizontal(), -1, 1); // how much accelerator? motor = Mathf.Clamp(default_input.GetVertical(), 0, 1); // how much brake? brake = -1 * Mathf.Clamp(default_input.GetVertical(), -1, 0); if (default_input.GetRespawn() && !isRespawning && canRespawn) { isRespawning = true; Respawn(); canRespawn = false; Invoke("resetRespawn", 2); } // first, we make sure that a weapon controller exists (otherwise no need to fire!) if (weaponControl != null) { // fire if we need to if (default_input.GetFire() && canFire) { // tell weapon controller to deal with firing weaponControl.Fire(); if (canPlayFireSound) { // tell our sound controller to play a pew sound BaseSoundController.Instance.PlaySoundByIndex(0, myTransform.position); canPlayFireSound = false; Invoke("ResetFireSoundDelay", timeBetweenFireSounds); } } } }
public override void Update() { // don't do anything until Init() has been run if (!didInit) { return; } // do the update in our base UpdateShip(); // check to see if we're supposed to be controlling the player before checking for firing if (!canControl) { return; } // fire if we need to if (fire_input) { // tell weapon controller to deal with firing weaponControl.Fire(); } }
protected virtual void UpdateState() { // if we are not allowed to control the weapon, we drop out here if (!canControl) { return; } if (thisGameObjectShouldFire) { // we use doFire to determine whether or not to fire right now doFire = false; // canFire is used to control a delay between firing if (canFire) { if (currentState == AIAttackState.random_fire) { // if the random number is over x, fire if (Random.Range(0, 100) > 98) { doFire = true; } } else if (currentState == AIAttackState.look_and_destroy) { if (Physics.Raycast(myTransform.position, myTransform.forward, out rayHit)) { // is it an opponent to be shot at? if (rayHit.transform.CompareTag(tagOfTargetsToShootAt)) { // we have a match on the tag, so let's shoot at it doFire = true; } } } else { // if we're not set to random fire or look and destroy, just fire whenever we can doFire = true; } } if (doFire) { // we only want to fire if we are on-screen, visible on the main camera if (onlyFireWhenOnscreen && !rendererToTestAgainst.IsVisibleFrom(Camera.main)) { doFire = false; return; } // tell weapon control to fire, if we have a weapon controller if (weaponControl != null) { // tell weapon to fire weaponControl.Fire(); } // set a flag to disable firing temporarily (providing a delay between firing) canFire = false; // invoke a function call in <fireDelayTime> to reset canFire back to true, allowing another firing session Invoke("ResetFire", fireDelayTime); } } }