Search Unity

Scripting 101 question

Discussion in 'Scripting' started by AaronC, Nov 5, 2006.

  1. AaronC

    AaronC

    Joined:
    Mar 6, 2006
    Posts:
    3,552
    Hi Im just trying to learn a few basics,I am trying to make a varible public, but I'm not quite there.
    Code (csharp):
    1.  
    2. function Start (){
    3. animation.Stop();
    4. yield WaitForSeconds(5);
    5. animation.Play();
    6. }
    This is my private var version, But To make the varible public?
    Code (csharp):
    1.  
    2. var "DelayTime":5 ;
    3. function Start (){
    4. animation.Stop();
    5. yield WaitForSeconds("Delaytime");
    6. animation.Play();
    7. }
    8.  
    Does whatever that comes after"var" Have to come from a specific list of commands? If so what are these commands classified as and where should I look in the reference-or maybe theres some other way of making the penny drop? I just havent quite got it yet...
    thanks
    AC
     
  2. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Change that to:

    var delayTime : int = 5;

    The format is:

    var variableName : type = value;

    Or you can do:

    var variableName : type;

    if you don't want a default value. Normally you'd use that form for GameObjects or Transforms or that sort of thing.

    Or you can do:

    var variableName = 5;

    which leaves it up to Unity to determine the type. That would result in variableName being an integer. Or:

    var variableName = 5.0;

    results in variableName being a float. I almost always define the type if only to remind myself what it is...I don't think it hurts anything....

    --Eric
     
  3. AaronC

    AaronC

    Joined:
    Mar 6, 2006
    Posts:
    3,552
    Thanks Eric
    Thats very helpful, and I got the Quaternion concept a bit better too.
    AC