private void Update() { actor.movement = new Vector2(Input.GetAxis(horizontalAxis), Input.GetAxis(verticalAxis)); if (Input.GetButtonDown(sprint)) { actor.Sprint(); } else if (Input.GetButtonDown(attack)) { actor.Attack(); } else if (Input.GetButtonDown(pickup)) { actor.Pickup(); } }
private void Update() { switch (state) { case State.Wander: if (visionTrigger.seesEnemy) { if (Random.value < 0.5f) { AudioSource.PlayClipAtPoint(screamSound, Camera.main.transform.position); movement = new Vector2(1, 0); nextDirectionChange = Time.time + timeBetweenMovementChange; } else { actor.Attack(); } } else { actor.movement = movement; if (Time.time > nextDirectionChange) { movement = new Vector2(Random.Range(-1f, 1f), Random.Range(-1f, 1f)); nextDirectionChange = Time.time + timeBetweenMovementChange; } } break; case State.Attack: movement = Vector2.zero; if (actor.state == CharacterActor.State.Idle) { state = State.Wander; } break; case State.Dead: movement = Vector2.zero; break; } }
// Update is called once per frame void Update() { Vector2 move = new Vector2(Input.GetAxisRaw("Horizontal"), Input.GetAxisRaw("Vertical")); if (move.sqrMagnitude < 0.2f) { move = Vector2.zero; } if (Input.GetButtonDown("Swap Weapon")) { actor.SwapWeapons(); } if (actor.CanMove) { if (!DialogUI.Instance.visible) { if (Input.GetButtonDown("Sprint")) { if (!actor.sprinting && actor.AttackCharge <= 1f) { actor.sprinting = true; actor.AttackCharge /= 2f; } } if (Input.GetButtonUp("Sprint")) { actor.sprinting = false; } if (move.sqrMagnitude <= 0f && actor.sprinting) { move = actor.TransformDirection(Vector2.right); } //Debug.Log("Moving towards" + actor.movementDirection + actor.IsMoving); actor.Move(move); } if (Input.GetButtonDown("Attack")) { if (UI.DialogUI.Instance.visible) { UI.DialogUI.Instance.OnNextDown(); } else if (actor.AttackCharge <= 1f) { actor.weaponCharging = true; actor.Attack(); } } if (Input.GetButtonUp("Attack")) { if (UI.DialogUI.Instance.visible) { UI.DialogUI.Instance.OnNextUp(); } else if (actor.weaponCharging) { if (actor.AttackCharge > 1f) { actor.Attack(); } actor.weaponCharging = false; } } if (actor.weaponCharging) { actor.weaponCharging = Input.GetButton("Attack"); } //actor.MoveToCheckingCollision(transform.position + (Vector3)(move * Time.deltaTime * tilesMovePerSecond * (actor.sprinting ? 2f : 1f) * (actor.AttackCharge > 1f ? 0.5f : 1f))); } var cam = Camera.main; var targetPos = actor.Animation.spriteRenderer.transform.position; Vector3 camDeltaPos = targetPos - cam.transform.position; float cameraEdgeX = (screenNumTilesWidth / 2f) - numTilesFromScreenEdgeTillCameraPan; float cameraEdgeY = (screenNumTilesHeight / 2f) - numTilesFromScreenEdgeTillCameraPan; if (camDeltaPos.x < -cameraEdgeX) { Camera.main.transform.position = new Vector3(targetPos.x + cameraEdgeX, Camera.main.transform.position.y, Camera.main.transform.position.z); } else if (camDeltaPos.x > cameraEdgeX) { Camera.main.transform.position = new Vector3(targetPos.x - cameraEdgeX, Camera.main.transform.position.y, Camera.main.transform.position.z); } if (camDeltaPos.y < -cameraEdgeY) { Camera.main.transform.position = new Vector3(Camera.main.transform.position.x, targetPos.y + cameraEdgeY, Camera.main.transform.position.z); } else if (camDeltaPos.y > cameraEdgeY) { Camera.main.transform.position = new Vector3(Camera.main.transform.position.x, targetPos.y - cameraEdgeY, Camera.main.transform.position.z); } }