0

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

bool shoot = Input.GetButtonDown("Fire1");
shoot |= Input.GetButtonDown("Fire2");
LearnCocos2D
  • 64,083
  • 20
  • 128
  • 214
eleodor
  • 51
  • 3
  • 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. – LearnCocos2D 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. – Henk Holterman Jan 29 '15 at 11:11
  • 3
    Where do we even begin to justify what a programmer "should have" or "should know"? – LearnCocos2D Jan 29 '15 at 11:18
  • At the very basics. SO is not a interactive tutorial site. – Henk Holterman Jan 29 '15 at 11:21

1 Answers1

1

is an OR assignment operator

is equivalento to:

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

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

Alan
  • 175
  • 7
  • 18