Flipping a 2D Sprite Animation in Unity 2D

后端 未结 5 1093
失恋的感觉
失恋的感觉 2020-12-30 07:04

I\'ve got a quick question regarding 2D Sprite animations that I haven\'t been able to find specifically answered anywhere:

I have a sprite with walk animations to t

5条回答
  •  旧时难觅i
    2020-12-30 07:17

    This is how I did it - almost the same as the other technique by Jestus with unity script.

    var facing : String = "right";
    
    function updateFacing(curr : String){
        if(curr != facing){
            facing = curr;
            var theScale : Vector3 = gameObject.transform.localScale;
            theScale.x *= -1;
            gameObject.transform.localScale = theScale;
        }
    }
    
    //put to use
    function controls(){
        if(Input.GetKey (KeyCode.LeftArrow)){
            updateFacing("left");
        } else if(Input.GetKey (KeyCode.RightArrow)){
            updateFacing("right");
        }      
    }
    

提交回复
热议问题