私はこの関数を持っています.2つのVector3引数と1つのintを渡したいので、float値を返すことができます。私は引数としてVector3とintを使用してもfloat値を返すことができますか? これは私のコードです:私はkeyworkd「戻る」と「オブジェクト」のキーワードを交換するときタイプ引数が異なる関数から浮動小数点数を返すにはどうすればよいですか?
//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));
}
}
それは私にこのエラーが発生します。 enter image description here
宣言や 'return distance;'で 'object'を' float'に変更することができます。 –
はい、すべての答えとコメントは答えを指します;) –