小编Noo*_*bie的帖子

如何从具有不同类型参数的函数返回浮点数?

我有这个函数,我想传递两个Vector3参数和一个int,所以我可以返回一个浮点值.即使我使用Vector3和int作为参数,我怎么能返回一个浮点值?这是我的代码:

//find other types of distances along with the basic one
public object  DistanceToNextPoint (Vector3 from, Vector3 to, int typeOfDistance)
{
    float distance;
    //this is used to find a normal distance
    if(typeOfDistance == 0)
    {
        distance = Vector3.Distance(from, to);
        return distance;
    }
    //This is mostly used when the cat is climbing the fence
    if(typeOfDistance == 1)
    {
       distance = Vector3.Distance(from, new Vector3(from.x, to.y, to.z));
    }
}
Run Code Online (Sandbox Code Playgroud)

当我用"return"keyworkd替换"object"关键字时,它给了我这个错误; 在此输入图像描述

c# methods unity-game-engine

1
推荐指数
1
解决办法
148
查看次数

标签 统计

c# ×1

methods ×1

unity-game-engine ×1