Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Newbie Question

Discussion in 'Scripting' started by vx3, Oct 29, 2007.

  1. vx3

    vx3

    Joined:
    Oct 25, 2007
    Posts:
    7
    Today is my first day with javascript (or any programming language for that matter) and it's been a very long day :)

    I've been going thru the tutorials on the unify wiki, and have been modifying the rock, paper, scissors game to try and figure out how it all works.

    I want to add a display to the game that states what the computer played, I figured out how to display the number the computer generates randomly but cannot for the life of me figure out the conditional syntax that creates a variable based on what the computer selects and output that in english (i.e. computer played: Rock or paper or scissors)

    I've seen many types of boolean statements in various online documents relating to javascript but cannot translate this into what I need...so...Help?

    TIA and Cheers,
    Morgan

    Here is the script of the finished GameManager from the wiki for reference:

     
  2. yangmeng

    yangmeng

    Joined:
    Dec 5, 2006
    Posts:
    573
    There's sure to be a more elegant way of doing this, but this should work:
    Duplicate the "ResultText" in the editor and name it "ComputerText" (you'll want to change it's position some to see it well) then add this to the top of the GameManager script (this is javascript):
    Code (csharp):
    1. var ComputerText : GUIText;
    Then add this script to the bottom of the GameManager script in the "// Set and show the results" section.
    Code (csharp):
    1.  
    2.     if (cIsRock) {
    3.         ComputerText.guiText.text = "Rock";
    4.     }
    5.     if (cIsScissors) {
    6.         ComputerText.guiText.text = "Scissors";
    7.     }
    8.     if (cIsPaper) {
    9.         ComputerText.guiText.text = "Paper";
    10.     }
    Then, you should just have to drag your ComputerText onto the GameManager's "ComputerText" public variable slot in the editor. That should do it...
     
  3. vx3

    vx3

    Joined:
    Oct 25, 2007
    Posts:
    7
    Thank you!!

    I was so close but all my attempts had variations of conditional statements in 1 block. Makes sense now.

    Thanks again
    morgan