- Home /
Cannot do anything except log form ui buttons
I am trying to move my player when a GUI button in the canvas is pressed . when the UI button is clicked the function is getting called (I know this as the log in the function is being displayed) but except for that unity ignores all other types of statements , I cant seem to change a variable or even translate the player directly from within the function
Here is my code
void Update ()
{
if(shouldMove)
Move();
ShapeShift();
FireBullets();
}
void Move()
{
Debug.Log (moveDirection);
var Horpadding = 0.7f;
float leftBound = Constants.leftBound + Horpadding, rightBound = Constants.RightBound - Horpadding;
transform.Translate (Vector2.right *moveDirection* PlayerSpeed*Time.deltaTime);
transform.position = new Vector3 (Mathf.Clamp (transform.position.x, leftBound, rightBound), transform.position.y);
}
public void ToggleMoving(int dir)
{
Debug.Log ("moving");
moveDirection = dir;
}
I am calling the ToggleMoving function in my ui i tried both button onClick() and pointer down in event trigger . i can see the function is getting called as the "moving" is displayed in the logs but the moveDirection does not change (from the log in the move function)
Please help
Is the boolean should$$anonymous$$ove set as true when you are pressing the button?
Your answer
Follow this Question
Related Questions
Can't make a bullet move in the direction the actor is facing 2 Answers
My player still keep moving when i unparent it form the car 2 Answers
I am trying to make an objective to go to the next level but there is an issue 1 Answer
Cannot move and jump with rigid body. 0 Answers
[2D] Moving the player 1 tile at a time using rigidbody movement 0 Answers