- Home /
Question by
uncopy2002 · Mar 14, 2014 at 07:37 PM ·
mathf
Extension Methods on Mathf not working
I'm trying to make some extension methods to Mathf that rounds, floors or ceils a value by a specific base (which base = 1 reduces to normal round/floor/ceil). Except that the code's not working, and the methods are at my extension methods class rather than Mathf struct:
using UnityEngine;
using System.Collections;
using System;
public static class ExtraMethods {
public static double Round2(this Mathf math, double num, double round)
{
return System.Math.Round (num / round) * round;
}
public static double Floor2(this Mathf math, double num, double round)
{
return num - num % round;
}
public static double Ceil2(this Mathf math, double num, double round)
{
return num - (num % round) + round;
}
}
Comment
Best Answer
Answer by whydoidoit · Mar 14, 2014 at 07:39 PM
You can't extend an already static class that way. You can only extend instances of objects (hence the this parameter). Perhaps you should just make a MathDouble class or something.
Or you could extend double to have rounding operators.
is this still the case? I know it's just syntactic sugar, but have a use case that would really benefit from an extension method like this.
Your answer
