- Home /
 
 
               Question by 
               SpaceSocks · May 08, 2014 at 07:22 AM · 
                variabledeclare  
              
 
              convert variables to C#?
var audio1 : AudioSource; var audio2 : AudioSource;
i see javascript examples all the time im just not sure how to declare these variables in c#
i know its dumb.
               Comment
              
 
               
               
               Best Answer 
              
 
              Answer by DMGregory · May 08, 2014 at 07:35 AM
The C# format is:
 Type variableName;
 
               Or with an initial value:
 Type variableName = initialValue;
 
               So, for example,
 AudioSource audio1;
 
               Note that if these are class members (not local variables in a function's scope), they will be private by default (and not displayed in the Inspector) unless you prefix the declaration with public (or [SerializeField] if you want it private and Inspectable):
 public int myPublicIntegerParameter;
 
              There's a handy little website for code conversion: Convert Unityscript to C#
Here's some links I found useful in converting between C# and JS :
Your answer