我是绝对的初学者。我目前正在使用javascript制作瞄准镜脚本,并且瞄准时我希望x和y的灵敏度都降至2。我尝试使用

GetComponent.<UnityStandardAssets.Characters.FirstPerson.MouseLook>().sensitivityX = 2;


但这不起作用。该行的错误是

NullReferenceException: Object reference not set to an instance of an object
Boo.Lang.Runtime.RuntimeServices.GetDispatcher (System.Object target, System.String cacheKeyName, System.Type[] cacheKeyTypes, Boo.Lang.Runtime.DynamicDispatching.DispatcherFactory factory)
Boo.Lang.Runtime.RuntimeServices.GetDispatcher (System.Object target, System.Object[] args, System.String cacheKeyName, Boo.Lang.Runtime.DynamicDispatching.DispatcherFactory factory)
Boo.Lang.Runtime.RuntimeServices.SetProperty (System.Object target, System.String name, System.Object value)
AimDownSights.Update () (at Assets/AimDownSights.js:33)


有谁知道如何访问FPSController中“鼠标外观”下拉列表的引用,以便更改敏感度?谢谢!

最佳答案

首先,您应该尽快使用C#,因为它具有比Javascript更多的功能。另外,与Unityscript相比,您在C#方面可以获得更多帮助。最后,Unityscript将来被终止的可能性很高,因此请立即做出决定。您可以找到Unity here的C#教程。

MouseLook脚本未在FirstPersonController脚本中公开。

我们将公开MouseLook。从Assets / Standard Assets / Characters / FirstPersonCharacter / Scripts目录中打开FirstPersonController.cs脚本,并将以下脚本添加到其中:

public MouseLook mouseLookCustom
{
    get { return m_MouseLook; }
}


而已。现在,我们公开了MouseLook实例。



修改鼠标的东西:

C#:

using UnityStandardAssets.Characters.FirstPerson;

public class Fpstest : MonoBehaviour
{
    FirstPersonController fps;

    // Use this for initialization
    void Start()
    {
        GameObject fpObj = GameObject.Find("FPSController");
        fps = fpObj.GetComponent<FirstPersonController>();
        fps.mouseLookCustom.XSensitivity = 5;
    }
}


Unityscript / Javascript:

#pragma strict
import UnityStandardAssets.Characters.FirstPerson;

var fps:FirstPersonController;

function Start () {
    var fpObj = GameObject.Find("FPSController");
    fps = GetComponent.<FirstPersonController>();
    fps.mouseLookCustom.XSensitivity = 5;
}

关于c# - 更改FirstPersonController MouseLook灵敏度,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/43623712/

10-09 04:22