How can I add Button movement to my Charakter (Android),How to make Charakter move with Buttons? (Android)
Hi, I tried to add Button movement to my game for days no but it doest work. Jumping works absolutely fine (Jumping is in another Script). I can´t find good tutorials. My Code: using System.Collections; using System.Collections.Generic; using UnityEngine;
public class MovementMobile : MonoBehaviour { private Rigidbody2D _rigidbody; bool moveLeft; bool moveRight; public float speed;
void start()
{
_rigidbody = GetComponent<Rigidbody2D>();
moveLeft = false;
moveRight = false;
}
public void MoveLeft()
{
moveLeft = true;
}
public void MoveRight()
{
moveRight = true;
}
public void Update()
{
if(moveLeft)
{
_rigidbody.velocity = new Vector2(speed, 0f);
}
if (moveRight)
{
_rigidbody.velocity = new Vector2(speed, 0f);
}
}
I put moveLeft and moveRight to events on the buttons but i just get errors. pls help me,Hello Guys, I want to add Button which controll the movement of my Charakter. The Keyboard Version runs perfectly but i just get lots of errors when i try the buttons. My Code: using System.Collections; using System.Collections.Generic; using UnityEngine;
public class MovementMobile : MonoBehaviour { private Rigidbody2D _rigidbody; bool moveLeft; bool moveRight; public float speed;
void start()
{
_rigidbody = GetComponent<Rigidbody2D>();
moveLeft = false;
moveRight = false;
}
public void MoveLeft()
{
moveLeft = true;
}
public void MoveRight()
{
moveRight = true;
}
public void Update()
{
if(moveLeft)
{
_rigidbody.velocity = new Vector2(speed, 0f);
}
if (moveRight)
{
_rigidbody.velocity = new Vector2(speed, 0f);
}
}
} I added MoveLeft and MoveRight as an event to my buttons but it doesn´t work pls help me