Answer the question
In order to leave comments, you need to log in
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
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;
}
}
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 обьект плавно падает вниз
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question