// Start is called before the first frame update void Start() { loadingBarScript = GameObject.FindWithTag("LoadingBar").GetComponent <LoadingBarScript>(); handlePivot = GameObject.FindWithTag("HandlePivot"); if (loadingBarScript && loadingBarScript.gameObject.activeSelf) { loadingBarScript.SetFillPercent(10); initializedBar = true; } }
// Update is called once per frame void Update() { if (neededHits == 0) { float xPos = transform.position.x; float percentageIn = (xPos - startingPoint.x) / (endingPoint.x - startingPoint.x); //Debug.Log(percentageIn); percentageIn *= 100; if (percentageIn > 0) { loadingBar.SetFillPercent(percentageIn); } } }
private void OnMouseDrag() { if (isOver) { Vector2 size = spriteRenderer.size; Vector2 newClick = Camera.main.ScreenToWorldPoint(Input.mousePosition); Vector2 deltaPos = newClick - clickedAt; clickedAt = newClick; if (deltaPos == Vector2.zero) { return; } boxCollider2d.offset += Vector2.right * deltaPos.x; spriteRenderer.size = new Vector2(size.x + deltaPos.x, size.y); loadingBarScript.SetFillPercent((spriteRenderer.size.x - 0.54f) * 10); } }
// Update is called once per frame void Update() { if (!initializedBar && loadingBarScript && loadingBarScript.gameObject.activeSelf) { loadingBarScript.SetFillPercent(10); initializedBar = true; } if (hasBeenGrabbed) { float mouseScroll = -Input.mouseScrollDelta.y * mouseScrollScale; loadingBarScript.AddFillPercent(mouseScroll * 10); transform.position += Vector3.right * (mouseScroll); handlePivot.transform.rotation = Quaternion.Slerp(handlePivot.transform.rotation, handlePivot.transform.rotation * quaternion.Euler(0, 0, mouseScroll * -100), Time.deltaTime * 30f); //transform.rotation = Quaternion.Slerp(transform); //loadingBarScript.AddFillPercent(); } }
void MoveBike() { var left = Input.GetKey(KeyCode.A) || Input.GetKey(KeyCode.LeftArrow); var right = Input.GetKey(KeyCode.D) || Input.GetKey(KeyCode.RightArrow); if (left) { btn = false; rb.AddForce(new Vector2(Time.deltaTime * speedModifier, 0), ForceMode2D.Impulse); //RotatePedal(); } if (right) { btn = true; rb.AddForce(new Vector2(Time.deltaTime * speedModifier, 0), ForceMode2D.Impulse); //RotatePedal(); } if (left || right) { SoundController.Instance.Play("Bicycle", 1); } else { SoundController.Instance.Pause("Bicycle"); } Vector3 currentPos = gameObject.transform.position; float p = (currentPos.x - startPos.x) / (endPos.x - startPos.x); loadingBarScript.SetFillPercent(p * 100f); RotateWheels(); RotatePedal(); }