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. Voting for the Unity Awards are OPEN! We’re looking to celebrate creators across games, industry, film, and many more categories. Cast your vote now for all categories
    Dismiss Notice
  3. Dismiss Notice

Math.Round

Discussion in 'Scripting' started by adamlukasik00936, Oct 12, 2018.

Thread Status:
Not open for further replies.
  1. adamlukasik00936

    adamlukasik00936

    Joined:
    Oct 12, 2018
    Posts:
    7
    Hi , I am just starting, using one of tutorials, and I can't use Mathf.Round - (both "Mathf" and "Round" do not change color indicating acknowledge of function)

    When I add "using System;" I can use Math. not Mathf. but Round do not work anyway.

    Should I update some library and how, or what?
     
  2. Vryken

    Vryken

    Joined:
    Jan 23, 2018
    Posts:
    2,106
    Did you also include
    using UnityEngine;
    ?
     
  3. adamlukasik00936

    adamlukasik00936

    Joined:
    Oct 12, 2018
    Posts:
    7
    I am using Microsoft Visual studio, but this should not make difference
     
  4. adamlukasik00936

    adamlukasik00936

    Joined:
    Oct 12, 2018
    Posts:
    7
    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine
     
  5. Vryken

    Vryken

    Joined:
    Jan 23, 2018
    Posts:
    2,106
    Try running your Visual Studio installer, clicking the "Modify" button on your installation, and then scroll down to see if the Unity Engine workload is checked. If not, check it and update your installation.
     
  6. fire7side

    fire7side

    Joined:
    Oct 15, 2012
    Posts:
    1,819
    It doesn't make sense that Math.Round doesn't work when Math is in your library. I don't know why it isn't reading Mathf. Maybe reinstall Visual Studio. I had to do it once when I upgraded.
     
  7. adamlukasik00936

    adamlukasik00936

    Joined:
    Oct 12, 2018
    Posts:
    7
    I have Visual Studia Tools For Unity 3.1.0.0
     
  8. adamlukasik00936

    adamlukasik00936

    Joined:
    Oct 12, 2018
    Posts:
    7
    ArgumentException: Value does not fall within the expected range.
    SyntaxTree.VisualStudio.Unity.Bridge.CompilationUnit.LanguageOf (SyntaxTree.VisualStudio.Unity.Bridge.CompilationUnit unit)
    SyntaxTree.VisualStudio.Unity.Bridge.CompilationUnit.CompilationUnits (System.String method)
    SyntaxTree.VisualStudio.Unity.Bridge.CompilationUnit.CompilationUnits ()
    SyntaxTree.VisualStudio.Unity.Bridge.ProjectSystem.UnitySolutionBuilder..ctor ()
    SyntaxTree.VisualStudio.Unity.Bridge.ProjectSystem.UnitySolutionBuilder.CreateSolutionFromAssetDatabase ()
    SyntaxTree.VisualStudio.Unity.Bridge.ProjectFilesGenerator.GenerateProject ()
    SyntaxTree.VisualStudio.Unity.Bridge.ProjectFilePostprocessor.OnPreGeneratingCSProjectFiles ()
    System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.Reflection/MonoMethod.cs:222)
    Rethrow as TargetInvocationException: Exception has been thrown by the target of an invocation.
    System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.Reflection/MonoMethod.cs:232)
    System.Reflection.MethodBase.Invoke (System.Object obj, System.Object[] parameters) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.Reflection/MethodBase.cs:115)
    UnityEditor.AssetPostprocessingInternal.OnPreGeneratingCSProjectFiles () (at C:/buildslave/unity/build/Editor/Mono/AssetPostprocessor.cs:204)
    UnityEditor.VisualStudioIntegration.SolutionSynchronizer.Sync () (at C:/buildslave/unity/build/Editor/Mono/VisualStudioIntegration/SolutionSynchronizer.cs:207)
    UnityEditor.SyncVS.SyncIfFirstFileOpenSinceDomainLoad () (at C:/buildslave/unity/build/Editor/Mono/SyncProject.cs:199)
    UnityEngine.GUIUtility:processEvent(Int32, IntPtr)


    and

    Assets/Scripts/UpgreadeManager.cs(31,26): error CS1501: No overload for method `Round' takes `2' arguments
     
  9. APSchmidt

    APSchmidt

    Joined:
    Aug 8, 2016
    Posts:
    4,459
  10. adamlukasik00936

    adamlukasik00936

    Joined:
    Oct 12, 2018
    Posts:
    7
    I am lerning from

    check 23:21, and my Mathf is black and unity shows problems shown in previous post.
     
  11. Lurking-Ninja

    Lurking-Ninja

    Joined:
    Jan 20, 2015
    Posts:
    9,900
    Please, check if you have two arguments when you call Mathf.Round. (Maybe you accidentally put coma instead of a decimal point?)
     
  12. adamlukasik00936

    adamlukasik00936

    Joined:
    Oct 12, 2018
    Posts:
    7
    I instaled updated Unity and Mathf still black, but Yelow alert is like in video, but still have this long red one in post up.
     
    Last edited: Oct 12, 2018
  13. The-Scripter

    The-Scripter

    Joined:
    Nov 10, 2009
    Posts:
    30
    System.Math takes 2 parameters so you can specify the number of decimal points. UnityEngine.Mathf only takes 1 parameter, and rounds to the nearest whole number. You've probably solved this by now, but it sounds like you were trying to use the Unity version like the System version.
     
  14. StephenWebb

    StephenWebb

    Joined:
    Feb 3, 2013
    Posts:
    9
    lol wut?
     
  15. StephenWebb

    StephenWebb

    Joined:
    Feb 3, 2013
    Posts:
    9
    I think you need to understand that the Math library of functions found in System IS NOT the same as the one in UnityEngine. The Math library found in System has no Mathf static class - in other words there is no Mathf.Round, only Math.Round
     
Thread Status:
Not open for further replies.