Search Unity

Remap Value

Discussion in 'Scripting' started by ValrikRobot, Mar 30, 2014.

  1. ValrikRobot

    ValrikRobot

    Joined:
    Jun 26, 2013
    Posts:
    206
    Ok im trying to write a script that will remap a value to a new range. In the example, the 'currentt' value will always be between zeroAngle and 180Angle. These are subject to change at runtime. I need a script that will translate the current int a corresponding value. ZeroAngle becomes 0 and 180Angle becomes 180.
    Code (csharp):
    1.  
    2. public HingeJoint H;
    3.     public float current=0;
    4.  
    5.  
    6.     public int ZeroAngle = -45;
    7.     public int 180Angle = 128;
    8.     // Use this for initialization
    9.     void Start () {
    10.    
    11.     }
    12.    
    13.     // Update is called once per frame
    14.     void Update () {
    15.         float RemappedValue = Remap (current);
    16.     }
    17.  
     
  2. mgear

    mgear

    Joined:
    Aug 3, 2010
    Posts:
    9,411
  3. ValrikRobot

    ValrikRobot

    Joined:
    Jun 26, 2013
    Posts:
    206
    JUST like that thank you.

    Seems such a simple thing to get stuck on. Cheers