- Home /
How to Stop Camera From Rotating when x,y,and z is equal to 90 degrees
Here is my code i need to stop the camera from rotating when its 90 degrees
  public float borderthickness = 10f;
     public float cameramovespeed = 10000f;
     
 
     // Update is called once per frame
     void Update()
     {
         Quaternion pos = transform.rotation;
 
   
             if (Input.mousePosition.y >= Screen.height - borderthickness && pos.x < 90f)
             {
                 pos.x -= cameramovespeed * Time.deltaTime;
                Debug.Log("up");
 
             }
            if (Input.mousePosition.y <= borderthickness && pos.x < 90f)
           {
             pos.x += cameramovespeed * Time.deltaTime;
    Debug.Log("down");
             
         }
         if (Input.mousePosition.x >= Screen.width - borderthickness && pos.y < 90f)
         {
             pos.y += cameramovespeed * Time.deltaTime;
             
    Debug.Log("right");
         }
         if (Input.mousePosition.x <= borderthickness && pos.y < 90)
         {
             pos.y -= cameramovespeed * Time.deltaTime;
                Debug.Log("left");
 
         }
         transform.rotation = pos;
         
 
               Comment
              
 
               
               
               Best Answer 
              
 
              Answer by BGOKMEN14 · May 13, 2018 at 05:02 AM
Hello!
  public float borderthickness = 10f;
      public float cameramovespeed = 10000f;
 bool canRotate = true;
 
      
  
      // Update is called once per frame
      void Update()
      {
          Quaternion pos = transform.rotation;
  
    
              if (Input.mousePosition.y >= Screen.height - borderthickness && pos.x < 90f && canRotate)
              {
                  pos.x -= cameramovespeed * Time.deltaTime;
                 Debug.Log("up");
  
              }
              if (pos.x == 90f || pos.y == 90f)
 {
 canRotate = false;
 }
 
You can add a bool called "canRotate" and do the changes I did above
Your answer
 
 
             Follow this Question
Related Questions
How to define a slider on script file? 1 Answer
Point-and-Click Camera movement script 1 Answer
Can I use GetComponents reference outside Of awake and start functions 1 Answer
Call function once in a while after a condition is met? 1 Answer
C# - Doesn't Unity support Expression Bodied Properties? 3 Answers
 koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                