简体   繁体   English

带有UI按钮的Unity Android字符控件

[英]Unity Android character controll with UI Buttons

So I'm trying to find a good tutorial which will explain how to controll character in 2D game when button is clicked (left, right, jump button). 因此,我试图找到一个不错的教程,该教程将说明如何在单击按钮(左,右,跳转按钮)时控制2D游戏中的角色。

All the tutorials I've found are outdated and not working. 我发现的所有教程都已过时,无法正常工作。

Here's what I've tryed: 这是我尝试过的:

Created Button on Canvas and added C# script to it. 在画布上创建了按钮,并向其中添加了C#脚本。 Now I know how to control character with keyboard, but scince I' not developing for PC, that's useless for me. 现在我知道如何用键盘控制字符,但是因为我不是为PC开发的,对我来说这没用。

I'm using something like this on PC: 我在PC上使用的是这样的东西:

GetComponent<Rigidbody2D>().velocity = new Vector3 (move * maxSpeed, GetComponent<Rigidbody2D>().velocity.y);

How can I convert it so it works for Android? 如何进行转换,使其适用于Android? For example, script that would move character to the right. 例如,将字符向右移动的脚本。

Thanks 谢谢

For controlling a character left right and forward and backward what you need is not just a button. 要左右左右控制角色,您需要的不仅仅是按钮。 You need a Virtual JoyStick . 您需要一个虚拟JoyStick You use button for things like jump. 您将按钮用于跳转之类的事情。 Watch this video, it is no outdated. 观看视频,这不是过时的。

For more examples about moving the character, look at the code in this question. 有关移动角色的更多示例,请查看问题中的代码。 The question contains code for moving the character with the keyboard and the answer explains how to move it with touch ( Virtual JoyStick ) on Android. 该问题包含使用键盘移动字符的代码,答案说明了如何在Android上通过触摸( Virtual JoyStick )来移动字符

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

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