Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Question How to multiply the same number or create a multiplier sentence?

Discussion in 'Scripting' started by Nacherdj, Aug 19, 2020.

  1. Nacherdj

    Nacherdj

    Joined:
    Aug 12, 2020
    Posts:
    8
    Hi;

    I am doing a head-tracking device that sends information through OSC messages. The yaw values are too low that I need to multiply the same number x 3 or x4 to be able to rotate the character at greater range.
    How I can do to multiply the same number for the times I need to increase the result?




    protected void MessageReceivedY(OSCMessage message)
    {
    if (message.ToFloat(out var value))
    {
    var euler = _target.eulerAngles;
    euler.y = value;

    _target.eulerAngles = euler;
    }
    }




    Thanks in advance.
     
  2. SkrenZz

    SkrenZz

    Joined:
    Apr 11, 2020
    Posts:
    26
    Use the asterisk (*) sign to multiply numbers.
    Example: int number = 3 * 4; // 12

    You can multiply the value with another number by writing:
    value = value * number;

    You can also write the exact same line as above in a more clean way which is recommended:
    value *= number; // same as value = value * number

    Is that what you were struggling with, or did I misunderstand the question?
     
    Joe-Censored and PraetorBlue like this.
  3. Nacherdj

    Nacherdj

    Joined:
    Aug 12, 2020
    Posts:
    8
    That is what I was looking for, thank you very much for your help
     
  4. SkrenZz

    SkrenZz

    Joined:
    Apr 11, 2020
    Posts:
    26
    Glad I could help! Good luck!