示例#1
0
    private void Update()
    {
        if (ballInMotion && body.velocity.magnitude == 0)
        {
            OnAimingStateChanged?.Invoke(true);
            ballInMotion = false;
        }

        if (body.velocity.magnitude != 0)
        {
            return;
        }

        if (Input.GetMouseButton(0))
        {
            force = Mathf.Clamp(force + 20f, 100f, maxForce);

            OnPowerChanged?.Invoke(force, maxForce);
        }

        if (Input.GetMouseButtonUp(0))
        {
            Vector2 forceVector = (Camera.main.ScreenToWorldPoint(Input.mousePosition) - transform.position).normalized;
            body.AddForce(forceVector * force);
            ballInMotion = true;

            OnStrokeEvent?.Invoke();
            OnAimingStateChanged?.Invoke(false);
            force = 0;
            OnPowerChanged?.Invoke(force, maxForce);
        }
    }
示例#2
0
 public void AdjustFlyWheelPowerBy(float value)
 {
     flywheelPower += value;
     OnPowerChanged?.Invoke(value);
 }