S
S
SkyCrusher2018-09-14 17:12:56
Game development
SkyCrusher, 2018-09-14 17:12:56

How to split the screen in half for input from Android devices?

The task is this: divide the screen of the device so that if you press on the left, the conditional ball jumps, and if you press on the right, it accelerates. What and how to use for this. If possible, more links and code examples. Thanks in advance)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Denis Gaydak, 2018-09-14
@SkyCrusher

well.
to start Input - https://docs.unity3d.com/ScriptReference/Input.html
about half the screen there are two options
1) invisible buttons (it's convenient to change position and size later)
2) track the coordinates of the mouse click (touch)
1) option. read about Canvas and generally examples of working with it
https://unity3d.com/ru/learn/tutorials/s/user-inte...
actually make two Buttons and put the required one in the OnClick event.
(look at the tutorials - it will become clear, everything is very trivial)
it will be problematic if you want to put several fingers on the screen at once - the unit usually just takes the middle position.
2) the option is not so flexible in terms of editing positions), but it’s much easier in terms of improvements and your own ideas.
approximately so.

private Rect leftPart = new Rect(0, 0, Screen.width / 2, Screen.height);
    private Rect rightPart = new Rect(Screen.width / 2, 0, Screen.width / 2, Screen.height);
    // Update is called once per frame
    void Update () {

        if(Input.GetMouseButton(0))//touch works too
        {
            if(leftPart.Contains(Input.mousePosition))
            {
                //jump
            }
            if(rightPart.Contains(Input.mousePosition))
            {
                //force
            }
        }

you may have to redo it for multitouch ( https://docs.unity3d.com/ScriptReference/Input.Get...
in fact, take not the position of the mouse, but the position of the wheelbarrow.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question