如何在 Unity 中 return Vector3
How to return Vector3 in Unity
我需要编写函数来 return vector3.
public Vector3 returnVec(){
//Some code
return gameObject.transform.position;
}
我想从另一个脚本调用这个函数,但出现错误:
"not all code paths return a value"
你能帮帮我吗?
此错误表明您在某处遗漏了 return
,在您注释为 "Some code" 的块中。您肯定有一些 if 情况,并且某些执行路径不以 return
.
结尾
类似于:
if (A){
//return a Vector3;
else if (B){
//instructions without a return;
//end of method;
}
我需要编写函数来 return vector3.
public Vector3 returnVec(){
//Some code
return gameObject.transform.position;
}
我想从另一个脚本调用这个函数,但出现错误: "not all code paths return a value"
你能帮帮我吗?
此错误表明您在某处遗漏了 return
,在您注释为 "Some code" 的块中。您肯定有一些 if 情况,并且某些执行路径不以 return
.
类似于:
if (A){
//return a Vector3;
else if (B){
//instructions without a return;
//end of method;
}