Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CSHARP

How to flip a character in Unity 2D

 //Checks if the left and right keys are pressed and flips the player accordingly
 //Make sure the player scale on the x axis is 1
    
    //Checks if the right key is pressed
    if (moveHorizontal > 0)
   	 {
     	rb2D.transform.localScale = new Vector3(1, transform.localScale.y, transform.localScale.z);
   	 }

	//Checks if Left Key is pressed
	else if (moveHorizontal < 0)
  	 {
       rb2D.transform.localScale = new Vector3(-1, transform.localScale.y, transform.localScale.z);
  	 }
 
PREVIOUS NEXT
Tagged: #How #flip #character #Unity
ADD COMMENT
Topic
Name
8+1 =