void Update() { if (Time.time > arrowNext) { arrowNext = arrowController.FireArrow(30); bowSound.Play(); } }
void Update() { ////Are we touching the screen and not already moving? if (Input.GetButtonDown("Fire1") && !moving) { ////Get touch position. Vector2 touchPosition = Camera.main.ScreenToWorldPoint(Input.mousePosition); ////Are we touching the horse, then move? ////Otherwise we are aiming the bow. if (movingCollider.OverlapPoint(touchPosition)) { moving = true; } else { aiming = true; } } ////If we are moving? if (moving) { ////Move toware the touch position. Vector2 touchPosition = Camera.main.ScreenToWorldPoint(Input.mousePosition); ////Make sure we are not flying :( float horseY = transform.position.y; if (horseY > 0) { touchPosition = new Vector2(transform.position.x, 0); } transform.position = Vector2.MoveTowards(transform.position, touchPosition, speed * Time.deltaTime); } ////If we are aiming? if (aiming) { Vector2 touchPosition = Camera.main.ScreenToWorldPoint(Input.mousePosition); var y = ArrowController.ArrowPoint.position.y - touchPosition.y; var x = ArrowController.ArrowPoint.position.x - touchPosition.x; angle = (Mathf.Atan2(-y, -x) * Mathf.Rad2Deg); BowArm.rotation = Quaternion.Euler(new Vector3(0, 0, angle)); FireHalo.rotation = Quaternion.Euler(new Vector3(0, 0, angle)); } ////Alway shoot the bow if (firing) { if (Time.time > arrowNext) { arrowNext = ArrowController.FireArrow(angle); bowSound.Play(); } } ////Reset controls then the finger is up. if (Input.GetButtonUp("Fire1")) { moving = false; aiming = false; } }