private void FixedUpdate() { facingRight = transform.localScale.x == -1.0f ? true : false; if (inputActive && Input.GetMouseButtonUp(0)) { float movePlayerVector = Input.mousePosition.GetScreenPositionFor2D().x; anim.SetFloat("speed", Mathf.Abs(movePlayerVector)); Vector2 posMouse = Input.mousePosition.GetScreenPositionFor2D(); if (posMouse.x < transform.position.x && facingRight) { Vector3 theScale = transform.localScale; theScale.x *= -1; transform.localScale = theScale; } else if (posMouse.x > transform.position.x && !facingRight) { Vector3 theScale = transform.localScale; theScale.x *= -1; transform.localScale = theScale; } StartLocation = transform.position.ToVector3_2D(); timer = 0; TargetLocation = WorldExtensions.GetScreenPositionFor2D(Input.mousePosition); startedTravelling = true; var encounterProbability = Random.Range(1, 100); if (encounterProbability < encounterChance && !GameState.PlayerReturningHome) { encounterDistance = (Vector3.Distance(StartLocation, TargetLocation) / 100) * Random.Range(10, 100); } else { encounterDistance = 0; } } else if (inputActive && Input.touchCount > 0) { StartLocation = transform.position.ToVector3_2D(); timer = 0; TargetLocation = WorldExtensions.GetScreenPositionFor2D(Input.GetTouch(0).position); startedTravelling = true; } //if(!inputReady && inputActive) //{ // TargetLocation = this.transform.position; // Debug.Log("Stopping player"); //} inputActive = inputReady; }
void Update() { if (inputActive && Input.GetMouseButtonUp(0)) { StartLocation = transform.position.ToVector3_2D(); timer = 0; TargetLocation = WorldExtensions.GetScreenPositionFor2D(Input.mousePosition); startedTravelling = true; } else if (inputActive && Input.touchCount > 0) { StartLocation = transform.position.ToVector3_2D(); timer = 0; TargetLocation = WorldExtensions.GetScreenPositionFor2D(Input.GetTouch(0).position); startedTravelling = true; } if (TargetLocation != Vector3.zero && TargetLocation != transform.position && TargetLocation != StartLocation) { transform.position = Vector3.Lerp(StartLocation, TargetLocation, MovementCurve.Evaluate(timer)); timer += Time.deltaTime; } if (startedTravelling && Vector3.Distance(StartLocation, transform.position.ToVector3_2D()) > 0.75) { this.GetComponent <Collider2D>().enabled = true; startedTravelling = false; } if (!inputReady && inputActive) { TargetLocation = this.transform.position; Debug.Log("stopping"); } inputActive = inputReady; }
void Update() { if (inputActive && Input.GetMouseButtonUp(0)) { StartLocation = transform.position.ToVector3_2D(); timer = 0; TargetLocation = WorldExtensions.GetScreenPositionFor2D(Input.mousePosition); startedTravelling = true; var EncounterProbability = Random.Range(1, 100); if (EncounterProbability < EncounterChance && !GameState.PlayerReturningHome) { EncounterDistance = (Vector3.Distance(StartLocation, TargetLocation) / 100) * Random.Range(10, 100); } else { EncounterDistance = 0; } } else if (inputActive && Input.touchCount == 1) { StartLocation = transform.position.ToVector3_2D(); timer = 0; TargetLocation = WorldExtensions.GetScreenPositionFor2D(Input.GetTouch(0).position); startedTravelling = true; var EncounterProbability = Random.Range(1, 100); if (EncounterProbability < EncounterChance && !GameState.PlayerReturningHome) { EncounterDistance = (Vector3.Distance(StartLocation, TargetLocation) / 100) * Random.Range(10, 100); } else { EncounterDistance = 0; } } if (TargetLocation != Vector3.zero && TargetLocation != transform.position && TargetLocation != StartLocation) { transform.position = Vector3.Lerp(StartLocation, TargetLocation, MovementCureve.Evaluate(timer)); timer += Time.deltaTime; } if (startedTravelling && Vector3.Distance(StartLocation, transform.position.ToVector3_2D()) > 0.5) { this.collider2D.enabled = true; startedTravelling = false; } if (EncounterDistance > 0) { if (Vector3.Distance(StartLocation, transform.position) > EncounterDistance) { TargetLocation = Vector3.zero; NavigationManager.NavigateTo("Battle"); } } if (!inputReady && inputActive) { TargetLocation = this.transform.position; Debug.Log("Stopping Player"); } inputActive = inputReady; }