我在做一个足球点球如游戏,我需要移动球移动了。现在,我使用这个代码:
I'm making a football-penalty like game and I need to move the ball on mobile too. I'm using this code now:
float moveHorizontal = Input.GetAxis("Horizontal"); float moveVertical = Input.GetAxis("Vertical"); Vector3 movement = new Vector3(moveHorizontal, 0.0f, moveVertical); rigidbody.AddForce(movement * speed * Time.deltaTime);
我怎样才能使运动系统,移动?
How can i make a movement System For mobile?
此外,还有就是控制球(当你通过一条线(就像保龄球一样),你只能改变它的位置1/10)someother代码。但他们都是基于这个代码...游戏脚本是C#...
Also, there is someother codes that control the ball (like when you pass a line (just like bowling) you can only change it's place 1/10). But they are based on this code... Game script is c#...
推荐答案使用轴触摸开关,这将有点困难。我建议阅读有关Touchscript( interactivelab.github.io/TouchScript/ )以及如何API的工作一般。你会需要做的就是当玩家触摸屏幕,你缓存联系,当他们碰你直呼其触摸比较其当前位置测量运动的方向。 。通过这样做,你可以刷卡路线
Switching this from using axis to touch will be a bit difficult. I recommend reading about Touchscript (interactivelab.github.io/TouchScript/) and how the API works in general. What you're going to need to do is when the player touches the screen, you cache that touch and while they're touching you measure the direction of the movement by comparing their first touch to their current position. By doing this you can get swipe directions.
像这样的东西可以让你开始:
Something like this could get you started:
public void OnTouchBegin( object sender, TouchEventArgs e ){ foreach( TouchPoint point in e.TouchPoints ){ firstTouchPosition = new Vector2( point.Position.x, point.Position.y ); } } public void OnTouchContinue( object sender, TouchEventArgs e ){ foreach( var point in e.TouchPoints ){ secondTouchPosition = new Vector2( point.Position.x, point.Position.y ); currentTouchMovement = new Vector2( ( secondTouchPosition.x - firstTouchPosition.x ), ( secondTouchPosition.y - firstTouchPosition.y )); currentTouchMovement.Normalize( ); } } public void OnTouchEnd( object sender, TouchEventArgs e ){ hasTouchEnded = true; }和你需要一些自定义代码来确定X和Y轴方向与触摸输入相对应。另外要小心屏幕坐标和游戏中的坐标为它们之间的区别相当多。这看起来令人生畏在第一,但也有一些工作,我保证它不是太糟糕了!希望这有助于!
And you'll need some custom code to determine the X and Y axis direction corresponds with the touch input. Also be careful about screen coordinates and in-game coordinates as they differ quite a bit. This looks daunting at first, but with some work I promise its not too bad! Hope this helps!
更多推荐
统一运动触摸
发布评论