Search Unity

I can't find the syntax manual

Discussion in 'Scripting' started by big12345, Jul 6, 2015.

  1. big12345

    big12345

    Joined:
    Jul 6, 2015
    Posts:
    14
    The manual used to include the unity .js syntax. It had stuff like the update function and OnTriggerEnter and OnMouseDown.
     
    Last edited: Jul 6, 2015
  2. SubZeroGaming

    SubZeroGaming

    Joined:
    Mar 4, 2013
    Posts:
    1,008
    Drop unity script, and use C#. Check out the MSDN by microsoft.
     
    Kiwasi likes this.
  3. LeftyRighty

    LeftyRighty

    Joined:
    Nov 2, 2012
    Posts:
    5,148
    not really... the syntax for what? unityscript? c#? shaders? what functionality are you trying to get at? etc.
     
  4. massey_digital

    massey_digital

    Joined:
    Apr 28, 2013
    Posts:
    94
    Last edited: Jul 6, 2015
  5. KelsoMRK

    KelsoMRK

    Joined:
    Jul 18, 2010
    Posts:
    5,539
    Kiwasi and massey_digital like this.
  6. Dustin-Horne

    Dustin-Horne

    Joined:
    Apr 4, 2013
    Posts:
    4,568
  7. big12345

    big12345

    Joined:
    Jul 6, 2015
    Posts:
    14
    Can I ask like a random question?

    for something like transform.Translate(1, 1, 1)... which is forward, which is right, and which is up
     
  8. SubZeroGaming

    SubZeroGaming

    Joined:
    Mar 4, 2013
    Posts:
    1,008
    sure
     
  9. big12345

    big12345

    Joined:
    Jul 6, 2015
    Posts:
    14
    I also can't find operators like say I want to use an if statement with ands and ors and equals or does not equal
     
  10. SubZeroGaming

    SubZeroGaming

    Joined:
    Mar 4, 2013
    Posts:
    1,008
    Check out my signature for some tutorials.
     
  11. Dustin-Horne

    Dustin-Horne

    Joined:
    Apr 4, 2013
    Posts:
    4,568
    Neither. it's transform.Translate(x, y, z);
    If you want to get the .forward it's a normalized direction that jus tells which direction your model is 'facing', so 0, 1, 0 would mean that you're facing straight up.

    It's the same as C# in that regard:

    And - &&
    OR - ||
    Equals - ==
    NotEquals - !=
     
  12. alexzzzz

    alexzzzz

    Joined:
    Nov 20, 2010
    Posts:
    1,447
    Q: Where can I find the official UnityScript/JavaScript language reference?
    A: It doesn't exist.

    Q: How is it possible?
    A: :D
     
    Kiwasi likes this.
  13. big12345

    big12345

    Joined:
    Jul 6, 2015
    Posts:
    14
    Hey Dustin thanks for the link... this is what I'm working on.

    http://pastebin.com/TGUNmwU3

    I would like to try the best I can to make it work using your link... meaning like the official syntax. I have it all as one script but I know it has to be in multiple scripts using different libraries.
     
  14. dreasgrech

    dreasgrech

    Joined:
    Feb 9, 2013
    Posts:
    205
    Here's a quick conversion of that file:
    Code (CSharp):
    1. using UnityEngine;
    2.  
    3. public class SomeScript : MonoBehaviour
    4. {
    5.     public GameObject prefab;
    6.  
    7.     private float Health;
    8.     private bool IsDead;
    9.  
    10.     private bool HasCorrectItem;
    11.  
    12.     private Texture Attack1;
    13.     private Texture Attack2;
    14.  
    15.     private Transform Projectile1;
    16.     private Transform Projectile2;
    17.  
    18.     private Transform DeadBody;
    19.  
    20.     private float Probability;
    21.  
    22.     private Transform transform;
    23.  
    24.     private void Awake()
    25.     {
    26.         transform = GetComponent<Transform>();
    27.     }
    28.  
    29.     private void Update()
    30.     {
    31. // for movement
    32.         if (Input.GetKeyDown("w"))
    33.             transform.Translate(0, 0, 0);
    34.  
    35.         if (Input.GetKeyDown("s"))
    36.             transform.Translate(0, 0, 0);
    37.  
    38.         if (Input.GetKeyDown("a"))
    39.             transform.Rotate(0, 0, 0);
    40.  
    41.         if (Input.GetKeyDown("d"))
    42.             transform.Rotate(0, 0, 0);
    43.  
    44.         if (Input.GetKeyDown("q"))
    45.             transform.Translate(0, 0, 0);
    46.  
    47.         if (Input.GetKeyDown("e"))
    48.             transform.Translate(0, 0, 0);
    49.  
    50.         if (Input.GetKeyDown("space"))
    51.             transform.Translate(0, 0, 0);
    52.  
    53. // for animation
    54.         if (Input.GetKeyDown("w"))
    55.             transform.Translate(0, 0, 0);
    56.  
    57.         if (Input.GetKeyDown("s"))
    58.             transform.Translate(0, 0, 0);
    59.  
    60.         if (Input.GetKeyDown("a"))
    61.             transform.Rotate(0, 0, 0);
    62.  
    63.         if (Input.GetKeyDown("d"))
    64.             transform.Rotate(0, 0, 0);
    65.  
    66.         if (Input.GetKeyDown("q"))
    67.             transform.Translate(0, 0, 0);
    68.  
    69.         if (Input.GetKeyDown("e"))
    70.             transform.Translate(0, 0, 0);
    71.  
    72.         if (Input.GetKeyDown("space"))
    73.             transform.Translate(0, 0, 0);
    74.  
    75. // for health and respawn
    76.         if (Health < 0)
    77.         {
    78.             IsDead = true;
    79.         }
    80.  
    81.         if (IsDead)
    82.         {
    83.             // transform.location(1, 1, 1)  // No idea what this is                      
    84.             IsDead = false;
    85.         }
    86.  
    87. // for spawning a dead body
    88.         if (IsDead)
    89.         {
    90.             Instantiate(DeadBody, Instantiate(prefab, new Vector3(i*2.0F, 0, 0), Quaternion.identity);
    91.         }
    92.  
    93. // for making the dead body have a lootable item based off of probability
    94.     }
    95.  
    96.     private void OnGUI()
    97.     {
    98. // for the projectiles
    99.         if (GUI.Button(new Rect(10, 70, 50, 30), Attack1))
    100.             Instantiate(Projectile1, Instantiate(prefab, new Vector3(i*2.0F, 0, 0), Quaternion.identity);
    101.  
    102.         if (GUI.Button(new Rect(10, 70, 50, 30), Attack2) && HasCorrectItem)
    103.             Instantiate(Projectile2, Instantiate(prefab, new Vector3(i*2.0F, 0, 0), Quaternion.identity);
    104.  
    105. // for an inventory
    106.  
    107. // for looting the item off the dead body
    108.  
    109.  
    110.     }
    111.  
    112.  
    113. // for clicking the dead body to change a variable
    114.  
    115. // for subtracting health
    116.     private void OnTriggerEnter(Collider other)
    117.     {
    118.         if (gameObject.tag == Projectile1.ToString())
    119.         {
    120.             Health -= 1;
    121.         }
    122.  
    123.         if (gameObject.tag == Projectile2.ToString())
    124.         {
    125.             Health -= 2;
    126.         }
    127.     }
    128. }
    Two problems though:

    1) where's the 'i' that's used in the methods coming from?
    2) What are you trying to accomplish with the line "transform.location(1, 1, 1)"?
     
  15. big12345

    big12345

    Joined:
    Jul 6, 2015
    Posts:
    14
    I messed up with where I have transforms for the part where it says // for animation... I also added something for checking for the correct item which I haven't figured out yet either and is just "// for checking to see if it has the correct item"

    http://pastebin.com/qrzx8x82

    I have lots of parts where I just have "// and then an explanation" of what I want... but that I haven't figured out how to implement it yet.
     
    Last edited: Jul 7, 2015
  16. Kiwasi

    Kiwasi

    Joined:
    Dec 5, 2013
    Posts:
    16,860
    Documentation for UnityScript doesn't exist. Unity has no plans to create the documentation. Most of the community have switched over to C#. There are some diehard UnityScript users, but their numbers are shrinking.
     
    Dustin-Horne likes this.
  17. big12345

    big12345

    Joined:
    Jul 6, 2015
    Posts:
    14
    Can someone show me where I can play an animation clip with an if statement?
     
  18. Dustin-Horne

    Dustin-Horne

    Joined:
    Apr 4, 2013
    Posts:
    4,568
    SubZeroGaming likes this.
  19. big12345

    big12345

    Joined:
    Jul 6, 2015
    Posts:
    14
    Thanks again Dustin

    How can I use OnMouseDown so that when I click a specific game object it spawns a variable?
     
  20. Dustin-Horne

    Dustin-Horne

    Joined:
    Apr 4, 2013
    Posts:
    4,568
    Step 1: Click the button
    Step 2: Please go through the tutorials and Learn section as this will be a painful and slow process asking one basic question at a time.
     
    Deleted User and Kiwasi like this.
  21. big12345

    big12345

    Joined:
    Jul 6, 2015
    Posts:
    14
    Whatever I give up then... I need step by step instructions you can't just expect me to be able to dig through literally everything in the universe and find exactly what I'm supposed to do... it doesn't make sense... my questions are so basic too
     
  22. Kiwasi

    Kiwasi

    Joined:
    Dec 5, 2013
    Posts:
    16,860
    Farewell. Hope you find a hobby more to your liking.

    For reference it wasn't everything in the universe. Just everything in the learn section.
     
  23. hpjohn

    hpjohn

    Joined:
    Aug 14, 2012
    Posts:
    2,190
    The tutorials are step by step instructions
     
    Kiwasi likes this.
  24. LeftyRighty

    LeftyRighty

    Joined:
    Nov 2, 2012
    Posts:
    5,148
    more than half the time spent coding (any form of coding, not just unity stuff) is learning how new stuff works and working out why the stuff you have isn't working. You will need to get used to the feeling of "digging through literally everything" if you want to write code.

    The learn section has short, to the point, example driven, step by step tutorial vids with sample code. Broken down into individual aspects of unity and also entire game projects. If you are saying going through those are "too much" I really think you're looking at the wrong hobby.

    Alternatively you could try to hire someone to teach you; this is the wrong forum section for that though.
     
    Kiwasi likes this.
  25. big12345

    big12345

    Joined:
    Jul 6, 2015
    Posts:
    14
    http://pastebin.com/BU23r7u4

    Check it out again... its all finished... its very basic... I want to figure out how to make it multiplayer
     
    Last edited: Jul 8, 2015
  26. LeftyRighty

    LeftyRighty

    Joined:
    Nov 2, 2012
    Posts:
    5,148
    congrats :D

    ok, a few suggested "look up this"...

    Input.GetAxis() and the input manager, so you don't have to hard code to specific keys and repeat so much in the input section
    http://docs.unity3d.com/ScriptReference/Input.GetAxis.html
    http://docs.unity3d.com/Manual/class-InputManager.html

    basically everything in the animation learn section, you are using the legacy animation system (it works, for now...)
    https://unity3d.com/learn/tutorials/modules/beginner/animation

    and again, everything in the new UI system learn section, OnGUI is the legacy old system which is more painful to work with once you start wanting to do anything "fancy"
    https://unity3d.com/learn/tutorials/modules/beginner/ui

    might want to think about breaking up the functionality into discrete components, health management, shooting, movement etc. Helps keep things tidy (good to learn when the scripts are still small) and means you can reuse code later without having to rewrite it.
     
  27. big12345

    big12345

    Joined:
    Jul 6, 2015
    Posts:
    14
    http://pastebin.com/WzdCUMvJ

    I revised it a little bit. I would really like to see if there is a way I can make it multiplayer. The way I think it would work is that this script would be attached to a prefab of a 3d object with animation clips for strafeing and running etc. And then the clients would be given these prefabs almost like a character

    I would want to make lots of different characters which drop different items. As you can see in the script if you click on "DeadBody2" it makes a texture called "Loot2" while this script spawns DeadBody1.
     
    Last edited: Jul 8, 2015