我有這個功能,我想傳遞兩個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));
}
}
當我用「迴歸」 keyworkd取代「對象」關鍵字它給了我這個錯誤; enter image description here
你可能希望在聲明和返回距離中把'object'改成'float'。 – 2017-10-05 13:50:29
是的,所有的答案和評論都指向了答案;) –