Advertisement
gameDevTeacher

Conditional Operators

Jun 10th, 2019
174
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.01 KB | None | 0 0
  1. // IF STATEMENT
  2.   if (moveX < 0)
  3.             { transform.localEulerAngles = new Vector3(0f, 0f, 15f); }
  4.             else { transform.localEulerAngles = new Vector3(0f, 0f, -15f); }
  5.  
  6. // CONDITIONAL EXPRESSION:
  7.             // Target Variable         Condition / if     Consequent / true      Alternative / false
  8.             transform.localEulerAngles = moveX < 0 ? new Vector3(0f, 0f, 15f) : new Vector3(0f, 0f, -15f);
  9.  
  10.             // If Condition is true, transform.localEulerangles is set to 0,0,15
  11.             // If the condition the "target variable" is set to be 0,0-15
  12.  
  13. // IF STATEMENT
  14. if (Input.GetKey(KeyCode.LeftShift))
            
  15. { _acceleration = _boost; }
            
  16. else { _acceleration = _base; }
            
  17.  
  18.  

// CONDITIONAL EXPRESSION
  19. // Target variable - _acceleration
          
  20. // Condition - Input.GetKey(KeyCode.LeftShift)
            
  21. // True - Boost
            
  22. // False - Base
  
  23.          
  24. _acceleration = Input.GetKey(KeyCode.LeftShift) ? _boost : _base;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement