Beispiel #1
0
    /// <summary>
    /// by accelerometer input x set angle of camera quateration and arms of player character
    /// </summary>
    void FixedUpdate()
    {
        float accelerationValue = (Input.acceleration.x * accelerometerInputMultiplier) + 1;

#if UNITY_EDITOR
        if (Input.GetJoystickNames().Length > 0)
        {
            accelerationValue = -1 * Input.GetAxis("Vertical2") + 1;
        }
        else
        {
            if (Input.GetAxis("Vertical") != 0)
            {
                accelerationValue = Input.GetAxis("Vertical") + 1;
            }
        }
        if (instantValue != -0.01f)
        {
            accelerationValue = instantValue;
        }
#endif

        float angle = 90 - (float)Math.Round((float)MathFuncs.equationX(accelerationValue, 2, 180), 0);
        angle *= 2;
        angle  = MathFuncs.forks(angle, 180, -180);
        angle  = MathFuncs.getValueInRange(angle, -90, 90);
        float currentAngle = transform.rotation.eulerAngles.z;
        currentAngle = MathFuncs.forks(currentAngle, 180, -180);

        float angleStep   = (angle - currentAngle) / 15;
        float targetAngle = currentAngle + angleStep;
        transform.rotation = Quaternion.Euler(new Vector3(0, 0, targetAngle));
        playerController.setArms(targetAngle);
    }
Beispiel #2
0
    /// <summary>
    /// set size of box collider depending on visible part of monster
    /// </summary>
    void setBoxColliderSize()
    {
        // 0 - h = 1.1, y = 0.25
        // -0.78 h = 0.1, y = 0.3
        // -0.875 h = 0, y = 0.39
        float h = MathFuncs.equationX(0.875f + transform.localPosition.y, 0.875f, 1.1f);
        float y = -0.25f + MathFuncs.equationX(-transform.localPosition.y, 0.875f, 0.64f);

        boxCol.size   = new Vector2(boxCol.size.x, h);
        boxCol.offset = new Vector2(boxCol.offset.x, y);
    }
Beispiel #3
0
    /// <summary>
    /// refresh state of hourglass
    /// </summary>
    /// <returns>return time left to end counting, if lower than zero is time which expired after finnish</returns>
    public float refresh()
    {
        float spentTime    = Time.time - timeStart;
        float valueTopSand = MathFuncs.equationX(spentTime, time, 1);

        if (valueTopSand > 1)
        {
            valueTopSand = 1;
        }
        topSand.size      = 1 - valueTopSand;
        botSand.size      = valueTopSand;
        fallingSand.size  = 1 - valueTopSand;
        topSand.value     = 0;
        botSand.value     = 0;
        fallingSand.value = 0;
        return(time - spentTime);
    }