0

What exactly does this operator |= do? I have this code for Unity in C#

bool shoot = Input.GetButtonDown("Fire1");
shoot |= Input.GetButtonDown("Fire2");
CodeSmile
  • 64,284
  • 20
  • 132
  • 217
eleodor
  • 51
  • 4
  • 1
    `a |= b` is equal to `a = a | b`. Read from : [`|=` Operator (C# Reference)](https://msdn.microsoft.com/en-us/library/h5f1zzaw.aspx) Next time, please use google first. – Soner Gönül Jan 29 '15 at 11:03
  • 3
    I find that question valid. It's rather difficult to search for "|=" even with a combination of keywords (C#, operator) on Google and finding a good answer for the question. – CodeSmile Jan 29 '15 at 11:07
  • 3
    A C# developer should have a [list of operators](https://msdn.microsoft.com/en-us/library/6a71f45d.aspx) handy. @LearnCocos2D: For that same reason this question will have little future value. – H H Jan 29 '15 at 11:11
  • 3
    Where do we even begin to justify what a programmer "should have" or "should know"? – CodeSmile Jan 29 '15 at 11:18
  • At the very basics. SO is not a interactive tutorial site. – H H Jan 29 '15 at 11:21

1 Answers1

2

is an OR assignment operator

is equivalento to:

shoot = shoot | Input.GetButtonDown("Fire2");

See: https://msdn.microsoft.com/en-us/library/h5f1zzaw.aspx

Alan
  • 185
  • 8
  • 19