Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/323.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/unity3d/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 无法转换方法组'###';到非委托类型UnityEngine.Vector3_C#_Unity3d - Fatal编程技术网

C# 无法转换方法组'###';到非委托类型UnityEngine.Vector3

C# 无法转换方法组'###';到非委托类型UnityEngine.Vector3,c#,unity3d,C#,Unity3d,我正试图模拟一个重力影响在统一的对象附近的对象与此脚本附加;为了做到这一点,我尝试向物体本身添加一个力。但是,我在other.attachedRigidbody.AddForce()中遇到了一个问题,我得到了以下错误: 无法将方法组“forceCalculation”转换为非委托类型“UnityEngine.Vector3”。考虑使用圆括号调用方法。 公共级天文馆力量:单一行为{ 公共浮力; 公共游戏物体天文馆核心; 公众浮动范围; 无效对撞机(对撞机其他){ if(距离(其他游戏对象)

我正试图模拟一个重力影响在统一的对象附近的对象与此脚本附加;为了做到这一点,我尝试向物体本身添加一个力。但是,我在
other.attachedRigidbody.AddForce()中遇到了一个问题,我得到了以下错误:

无法将方法组“forceCalculation”转换为非委托类型“UnityEngine.Vector3”。考虑使用圆括号调用方法。
公共级天文馆力量:单一行为{
公共浮力;
公共游戏物体天文馆核心;
公众浮动范围;
无效对撞机(对撞机其他){
if(距离(其他游戏对象)<范围){
other.attachedRigidbody.AddForce(forceCalculation(other.gameObject)、ForceMode.Acceleration);
}
}
公共浮动距离(游戏对象其他){
浮动距离=矢量3.距离(其他.transform.position,transform.position);
返回距离;
}
公共矢量3方向(游戏对象其他){
Vector3方向=transform.position-other.gameObject.transform.position;
返回方向;
}
公共浮动乘数(游戏对象其他){
浮动乘数=范围-距离(其他);
回报乘数;
}
公共矢量3力计算(游戏对象其他){
力计算=方向(其他)*乘数(其他);
收益率计算;
}
}
forceCalculation()
中,您返回的是
forceCalculation()
方法,您应该做什么:

...
public Vector3 forceCalculation(GameObject other){
    Vector3 calculation = direction(other) * multiplier(other);
    return calculation;
}
第一行声明了一个名为
forceCalculation
的方法

然后,第二行尝试将向量3分配给以前注册的名称
forceCalculation
(这是一种方法)

通过声明变量修复此问题:


相隔几秒钟!
...
public Vector3 forceCalculation(GameObject other){
    Vector3 calculation = direction(other) * multiplier(other);
    return calculation;
}
public Vector3 forceCalculation(GameObject other) {
    forceCalculation = direction(other) * multiplier(other);
    return forceCalculation;
}
public Vector3 forceCalculation(GameObject other) {
    Vector3 forceCalculation = direction(other) * multiplier(other);
    return forceCalculation;
}