// Start is called before the first frame update void Start() { switch (Application.platform) { case RuntimePlatform.OSXEditor: case RuntimePlatform.OSXPlayer: shoot = (tag == "Player1_obj" ? "shoot-1-mac" : "shoot-2-mac"); break; case RuntimePlatform.WindowsEditor: case RuntimePlatform.WindowsPlayer: shoot = (tag == "Player1_obj" ? "shoot-1-pc" : "shoot-2-pc"); break; default: Debug.LogError("Mappings not setup for operating systems other than Windows or Mac OS"); break; } reloadTimer = 0f; bullets = new List <Bullet>(); // Start counter at 0, used in RecycleBullets() objectPoolCounter = 0; // Sets initial state for shooting SM state = SHOOT_States.WAIT; tc = GetComponent <TankController>(); shootSound = GetComponent <AudioSource>(); GameObject manager = GameObject.Find("GameManager"); cheater = (manager == null ? null : manager.GetComponent <CheatManager>()); Assert.IsTrue(cheater != null, "CheatManager couldn't be found from ShootController.\n" + "Does your scene have an object called \"GameManager\"\n" + "and does that object have a CheatManager component?"); }
/// <summary> /// A state machine that determines how fast and how often to fire a bullet, /// even if the fire button is pressed many times or held down for a while. /// </summary> /// <param name="buttonPressed">If set to <c>true</c> button pressed.</param> private void FireRateStateMachine(bool buttonPressed) { switch (state) // Transitions { case SHOOT_States.WAIT: if (buttonPressed) { state = SHOOT_States.FIRE; } break; case SHOOT_States.FIRE: state = SHOOT_States.COUNT_ON; break; case SHOOT_States.COUNT_ON: if (reloadTimer >= reloadTime && buttonPressed) { state = SHOOT_States.WAIT; } if (reloadTimer < reloadTime && !buttonPressed) { state = SHOOT_States.COUNT_OFF; } break; case SHOOT_States.COUNT_OFF: if (reloadTimer >= reloadTime && !buttonPressed) { state = SHOOT_States.WAIT; } if (buttonPressed) { state = SHOOT_States.COUNT_ON; } break; default: Debug.LogError("Not supposed to be here - transition sm"); break; } switch (state) // Actions { case SHOOT_States.WAIT: reloadTimer = 0f; break; case SHOOT_States.FIRE: // Adjust shootSound.clip if cheats are enabled bool amIP1 = taggyboi.isP1Tag(this.gameObject.tag); shootSound.clip = cheater.notifyShot(amIP1); // does not modify if cheat is not active reloadTimer = 0f; Fire(true); shootSound.Play(); break; case SHOOT_States.COUNT_ON: reloadTimer += Time.fixedDeltaTime; break; case SHOOT_States.COUNT_OFF: reloadTimer += Time.fixedDeltaTime; break; default: Debug.LogError("Not supposed to be here - action sm"); break; } }