简体   繁体   English

Unity操纵杆方法C#

[英]Unity Joystick method C#

I'm using Unity, and am trying to use the Joystick namespace. 我正在使用Unity,并且正在尝试使用Joystick命名空间。 but whenever I try to declare a joystic it says the namespace isn't valid. 但每当我尝试声明一个joystic时,它说命名空间无效。

Here are the libraries I am using: 这是我正在使用的库:

    using UnityEngine;
    using System.Collections;
    using Riverscout;

And this is the code that gives me the error: 这是给我错误的代码:

    public Joystick moveJoystick;

Can anyone tell me what library I need to use to make this work? 任何人都可以告诉我我需要使用哪个库来完成这项工作? Thanks in advance. 提前致谢。

The UnityEngine namespace doesn't contain any class named Joystick . UnityEngine命名空间不包含任何名为Joystick类。

You can, however, access joystick input that has been set up in the Input Manager by querying Input.GetAxis() . 但是,您可以通过查询Input.GetAxis()来访问已在Input Manager中设置的操纵杆输入。

Suppose you set up a joystick to control two axes, named "Joy0x" and "Joy0y", you could then get the input like so: 假设您设置了一个操纵杆来控制两个轴,名为“Joy0x”和“Joy0y”,那么您可以像这样得到输入:

function Update() {
    var x = Input.GetAxis("Joy0x");
    var y = Input.GetAxis("Joy0y");
    transform.Rotate(x, y, 0); //rotate attached GameObject
}

I imagine many people have posted joystick helper scripts. 我想很多人都发布了操纵杆助手脚本。 If you're working with one of those, please mention it. 如果您正在与其中一个合作,请提及它。

Joystick.js is included in Standard Assets (Mobile) package. Joystick.js包含在标准资产(移动)包中。 It's also used by a plethora of other 3rd party Unity Developers such as EasyTouch, EasyJoystick, Touch UI, UI Touch, and countless others. 它也被许多其他第三方Unity开发人员使用,例如EasyTouch,EasyJoystick,Touch UI,UI Touch和其他无数人。 But natively the Unity3D namespace doesn't contain Joystick like @rutter said. 但本地Unity3D命名空间不包含操纵杆,如@rutter所说。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM