【发布时间】:2017-10-05 13:48:50
【问题描述】:
我有这个函数,我想传递两个 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));
}
}
当我用“return”keyworkd 替换“object”关键字时,它给了我这个错误; enter image description here
【问题讨论】:
-
您可能希望将声明中的
object更改为float和return distance;。 -
是的,所有答案和 cmets 都指向答案;)