/// <summary> /// Update is called every frame, if the MonoBehaviour is enabled. /// </summary> private void Update() { if (_fireable == null) { return; } var deltaTime = Time.deltaTime; if (FrameRate > 0) { deltaTime = 1f / FrameRate; } _timer -= deltaTime; if (_timer < 0) { _fireable.Fire(new DanmakuConfig { Position = transform.position, Rotation = transform.eulerAngles.z * Mathf.Deg2Rad, Speed = Speed, AngularSpeed = AngularSpeed, Color = Color }); _timer = 1f / FireRate.GetValue(); } }
// Update is called once per frame void Update() { // Pause menu if (Input.GetKeyDown(StartButton)) { GameManager.instance.pauseMenu.Toggle(); } if (Game.Paused()) { float lsVert = GetAxis("Vertical"); if (!ls_pressed && Mathf.Abs(lsVert) > lsPressThreshold) { ls_pressed = true; if (lsVert > 0f) { } else { } } return; } if (allInputDisabled) { return; } //aiming and firing Vector2 aim_raw = new Vector2(0, 0); if (playerNum == keyboardControlledPlayer) { if (Input.GetKey(KeyCode.I)) { aim_raw.y += 1; } if (Input.GetKey(KeyCode.K)) { aim_raw.y -= 1; } if (Input.GetKey(KeyCode.J)) { aim_raw.x -= 1; } if (Input.GetKey(KeyCode.L)) { aim_raw.x += 1; } } if (aim_raw == new Vector2(0, 0)) { aim_raw = new Vector2(GetAxis("Horizontal_R"), GetAxis("Vertical_R")); } aim_raw = Vector2.ClampMagnitude(aim_raw, 1.0f); if (aim_raw.sqrMagnitude < epsilon) { aim_raw = Vector2.zero; aimIndicator.GetComponent <SpriteRenderer>().enabled = false; } else if (!inventory.Get() || inventory.Get().GetComponent <Fireable>()) { aimIndicator.GetComponent <SpriteRenderer>().enabled = true; } Vector2 aim = aim_raw.normalized; bool keyboardFire = false; if (playerNum == keyboardControlledPlayer) { keyboardFire = Input.GetKeyDown(KeyCode.Space); } float trigger = GetAxis("RTrigger"); if ((!rt_pressed && trigger > triggerPressThreshold) || keyboardFire) { //fire weapon/tool if aiming, else switch inventory slots rt_pressed = true; if (aim.Equals(Vector2.zero)) { //inventory.IncSlot(); } else { //print("activating held item"); if (inventory.Get()) { Fireable f = inventory.Get().GetComponent <Fireable>(); if (f) { f.Fire(aim, gameObject); } } else { Punch(aim); } } } if (rt_pressed && trigger < triggerReleaseThreshold) { rt_pressed = false; } //debug aimIndicator.transform.position = (Vector2)transform.position + aim_raw; float trigger_percentage = (trigger + 1) / 2; Color trigger_color = (1 - trigger_percentage) * GetComponent <SpriteRenderer>().color; aimIndicator.GetComponent <SpriteRenderer>().color = new Color(trigger_color.r, trigger_color.g, trigger_color.b); float ltrigger = GetAxis("LTrigger"); if (!lt_pressed && ltrigger > triggerPressThreshold) { //do not switch inventory slot lt_pressed = true; //inventory.DecSlot(); } if (lt_pressed && ltrigger < triggerReleaseThreshold) { lt_pressed = false; } if (rb.velocity.sqrMagnitude > float.Epsilon * float.Epsilon) { timeSinceLastMoved = 0f; idle = false; longIdle = false; } else { if (timeSinceLastMoved > timeUntilIdle) { idle = true; } if (timeSinceLastMoved > timeUntilLongIdle) { longIdle = true; } timeSinceLastMoved += Time.deltaTime; } if (idle && !idleLF) { GameManager.GetTextOverlayHandler(playerNum).AppearWords(); } else if (!idle && idleLF) { GameManager.GetTextOverlayHandler(playerNum).DisappearWords(); } if (longIdle && !longIdleLF) { GameManager.GetTextOverlayHandler(playerNum).AppearDefinitions(); } else if (!longIdle && longIdleLF) { GameManager.GetTextOverlayHandler(playerNum).DisappearDefinitions(); } idleLF = idle; longIdleLF = longIdle; ////Interact with world if (Input.GetKeyDown(AButton) || (me.playerNum == keyboardControlledPlayer && (Input.GetKeyDown(KeyCode.Space) || Input.GetKeyDown(KeyCode.E)))) { Interact(); } else if (Input.GetKeyDown(BButton) || (me.playerNum == keyboardControlledPlayer && (Input.GetKeyDown(KeyCode.DownArrow) || Input.GetKeyDown(KeyCode.R)))) { Drop(); } ////Adjust camera height out if (Input.GetKeyDown(YButton) || (me.playerNum == keyboardControlledPlayer && Input.GetKeyDown(KeyCode.LeftShift))) { camScript.ToggleZoom(zoomIn: false); } ////Adjust camera height in if (Input.GetKeyDown(XButton) || (me.playerNum == keyboardControlledPlayer && Input.GetKeyDown(KeyCode.RightShift))) { camScript.ToggleZoom(zoomIn: true); } ////Change which item is active if (Input.GetKeyDown(LeftBumper) || (me.playerNum == keyboardControlledPlayer && Input.GetKeyDown(KeyCode.LeftArrow))) { inventory.DecSlot(); } else if (Input.GetKeyDown(RightBumper) || (me.playerNum == keyboardControlledPlayer && Input.GetKeyDown(KeyCode.RightArrow))) { inventory.IncSlot(); } //make keyboardControlledPlayer adjustable by keyboard if (Input.GetKeyDown(KeyCode.Alpha1)) { keyboardControlledPlayer = 1; } else if (Input.GetKeyDown(KeyCode.Alpha2)) { keyboardControlledPlayer = 2; } else if (Input.GetKeyDown(KeyCode.Alpha3)) { keyboardControlledPlayer = 3; } else if (Input.GetKeyDown(KeyCode.Alpha4)) { keyboardControlledPlayer = 4; } else if (Input.GetKeyDown(KeyCode.Alpha0)) { keyboardControlledPlayer = 0; } }
public void Fire(Transform owner, Transform position, IDamager damager) { Fireable.Fire(owner, position, damager); }