angle 发表于 2013-1-25 02:05

VirtualJoystickRegion 虚拟摇杆插件


It solves many problems you face when trying to code a joystick, so if you are learning about it you may want to take a look. Also it is somewhat resolution independant so you dont have to worry about adjusting its size neither position.
This sample works within a "region" of the screen where the joystick adjusts its position to the player's finger if he taps inside that region.
It also work inside a circular boundary instead of a square and it can detect double taps too.
It does not use OnGUI(), its GUItextures and it does not need collision detection to work; very simple to use:

1) Create an empty Game Object.
2) Add the VirtualJoystickRegion.cs script to that object.
3) Use square textures for the "Joytick 2D" and "Background 2D" fields.
4) Adjust the "Active Color" and "Inactive Color" values as you wish, and its ready to go.

Note:
The Joystick outputs two global variables for you to work with, VJRvector and VJRnormals.
To get real screen space values, you query "VirtualJoystickRegion.VJRvector".
To get normalized joystick values, ideal numbers to work with, you query "VirtualJoystickRegion.VJRnormals".
If you dont like big names you may want to rename the "VirtualJoystickRegion" class to just "VJR".



dilly123 发表于 2013-1-25 10:54

哇 好厉害噢{:5_397:}

shengbin88 发表于 2013-1-27 17:29

是啊,好厉害

xenomaya 发表于 2013-7-26 18:36

谢谢分享了{:5_404:}

rainie 发表于 2013-7-29 10:07


也不能一竿子打死呀!{:soso__11174995096617402082_3:}

SEVENSKY 发表于 2017-2-21 17:08

真心顶

349061667 发表于 2017-2-21 17:15

说的非常好

mydesire1218 发表于 2017-2-21 17:05

很好哦

春到湘江 发表于 2017-2-21 16:53

不错不错

酷克数字 发表于 2017-2-21 17:03

LZ真是人才
页: [1]
查看完整版本: VirtualJoystickRegion 虚拟摇杆插件