X
X
XDecent2020-07-01 15:08:30
Mobile development
XDecent, 2020-07-01 15:08:30

How to make normal touch reading in unity?

The bottom line is that you need the hero to constantly fly up when you press 1, and if you press it again, it’s already down. implement it in unity for phones.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
G
GFX Data, 2020-07-02
@XDecent

Sample code in Update():

var touches = Input.touches;
        foreach (var t in touches)
        {
            switch (t.phase)
            {
                case (TouchPhase.Began): // Вверх
                    break;
                case (TouchPhase.Stationary):// Висим на месте
                    break; 
                case (TouchPhase.Ended): // Вниз
                    break; 
            }
        }

Z
zZaKko, 2020-07-01
@zZaKko

It is necessary to read different keystrokes:

public Gameobject obj; //Префаб игрока
public int c; //Счетчик положения

void Update(){
if(Input.GetKey(KeyCode.Space))//При зажатии
c = 3;//Положение игрока в воздухе
else c = 1;
if(Input.GetKeyUp(KeyCode.Space) && c == 1)//При нажатии с отжатием
c = 2; //Положение падения
else if(Input.GetKeyUp(KeyCode.Space) && c == 2)//При нажатии с отжатием
c = 1;//Положение взлета

if(c == 1)
obj.transform.position += new Vector3(0f ,1f * Time.deltaTime, 0f); //По вектору y обьект плавно летит вверх
esle if(c == 2)
obj.transform.position -= new Vector3(0f ,1f * Time.deltaTime, 0f); //По вектору y обьект плавно падает вниз
}

Something like this.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question