- Home /
 
Unity crashing and LocalScale not working
Hi, so I'm trying to get the my enemy and player sprites to flip whenever they face the other direction. Right now, I have it just use the negative of whatever the player or enemies change direction. The only thing is, it isn't working and it is crashing unity anytime I play. I you could help me out, I'd greatly appreciate it!
     public bool FacingRight = true;
     public float Righty = 1f;
     public float Lefty = 1f;
 
         void Update ()
         {
                 if (transform.rotation.eulerAngles.z > 90 && transform.rotation.eulerAngles.z < 270 && FacingRight == true) {
                         FacingRight = false;
                         transform.localScale += new Vector3 (transform.localScale.x, transform.localScale.y, transform.localScale.z);
                 } 
                 if (transform.rotation.eulerAngles.z < 90 || transform.rotation.eulerAngles.z > 270 && FacingRight == false) {
                         FacingRight = true;
                         transform.localScale += new Vector3 (transform.localScale.x, transform.localScale.y, transform.localScale.z);
                 }
         }
 
              
               Comment
              
 
               
               
               Best Answer 
              
 
              Answer by Xysch · Feb 24, 2015 at 10:58 PM
I didn't catch this before but the problem was that the
 transform.localScale += new Vector3 (transform.localScale.x, transform.localScale.y, transform.localScale.z);
 
               should have been
 transform.localScale = new Vector3 (transform.localScale.x, transform.localScale.y, transform.localScale.z);
 
               Just that simple little +. I should be more careful.
Your answer
 
             Follow this Question
Related Questions
Distribute terrain in zones 3 Answers
LocalScale not working idealy 1 Answer
Unity streching sprite gameobject to fit two positions. 1 Answer
Multiple Cars not working 1 Answer
Sprite Direction using transform.localRotation probelm 2 Answers