Search Unity

  1. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Unity Game Development Book

Discussion in 'Community Learning & Teaching' started by Merries, Jul 24, 2009.

  1. Raptor5399

    Raptor5399

    Joined:
    Sep 25, 2007
    Posts:
    94
    It was the space between "Battery GUI", as the game object is named BatteryGUI. Thus Battery GUI did not exist.

    If you create a script called PlayerCollisions and go to apply it to a game object through Component>Scripts and select the script, it will be called Player Collisions there. Unity auto spaces where there is capitalization. So I made the incorrect assumption that spaces in names were irrelevant.

    I do not like this behavior and would prefer Unity to leave things named what I named them.

    CEH
     
  2. RHD

    RHD

    Joined:
    Mar 30, 2009
    Posts:
    719
    A convention is a convention and as long as everyone knows about it it's probably fine.

    Thanks for flagging up this one!
     
  3. willgoldstone

    willgoldstone

    Unity Technologies

    Joined:
    Oct 2, 2006
    Posts:
    794
    Hi guys

    Yes I suppose that is somewhat misleading, apologies for not flagging it up, I guess I have just always been used to it, its hard when you're writing a 'from scratch' book to get every detail across - you kind of have to 'unlearn what you have learned' as yoda would put it. I meant to mention it on page 120 but I must have missed it, apologies.

    Debating it as a feature however I quite like it - it makes the menu look neat and gives new users (who it doesn't trip up!) a feeling that they're building part of the tool they're working with, an empowering part of the learning process.

    But to be clear, any convention of scripting must be followed strictly, cases first of all and any variable names and class (script) names cannot have spaces in and also cannot start with a number.

    Hope you are enjoying the rest of the book?

    Cheers

    Will
     
  4. RHD

    RHD

    Joined:
    Mar 30, 2009
    Posts:
    719
    Will, do not beat yourself up- as they say in America, it's a great book and there will inevitably be tricky bits here and there, not least because Unity just released a new version which changes a few things, but mostly because it's a really complex subject and explaining it as well as you do is a rare talent.

    It's a great book. I've not had time to work through it all yet but most of what I need is in there I think.

    So when are you doing one for the iPhone version? No pressure!
     
  5. gamenut30111

    gamenut30111

    Joined:
    Nov 7, 2009
    Posts:
    399
    does it teach any modeling or is it mainly for scripting?
     
  6. willgoldstone

    willgoldstone

    Unity Technologies

    Joined:
    Oct 2, 2006
    Posts:
    794
    I don't cover modelling, but assets are provided that you'd need for the book..

    Will ^_^
     
  7. WinningGuy

    WinningGuy

    Joined:
    Aug 10, 2009
    Posts:
    884
    Great contribution to the community Will!

    We picked up your book here at work. Great stuff so far.

    Are you working on a 2nd Edition that includes some of the new tools in Unity, like the Animation Editor?

    And how about adding C# and Boo scripts?

    And how about giving me a new car?

    ...or am I asking for too much?


    :D
     
  8. Raptor5399

    Raptor5399

    Joined:
    Sep 25, 2007
    Posts:
    94
    To each their own. I prefer consistency above all else, hard to have logic without it ;)

    Yoda was right :p

    Yes Ive been enjoying the book, need to get some time to get back to it though. Lots going on at the moment.

    Congrats on the book by the way.

    CEH
     
  9. uhahaha

    uhahaha

    Joined:
    Jan 5, 2010
    Posts:
    42
    (1) chapter 7 p.202

    10th line from to top you need to add .collider after ("campfire")

    if(hit.collider.gameObject == GameObject.Find("campfire")){
    }

    -->
    if(hit.collider.gameObject == GameObject.Find("campfire").collider){
    }

    (2) Suggestion: After finding matches setting fire, you bump into camp fire see "I'll need smoe match to..." message, which is kinda odd. So, we need another if(fire is set){...} statement to suppress that.

    (3) Chapter 8. p. 211. Step 1. When I saved the Island Level other than the Asset folder, I culdn't find IslandLevel asset in the project panel. So, this needs to be clarified to the reader.
    _________________
     
  10. sonysdp182

    sonysdp182

    Joined:
    Jan 9, 2010
    Posts:
    2
    Hi,Sony here.
    Is there any one who help me?I am Engi. student and I want to go in .NET field.So if i want to learn from basics then which book is suits me and ya also inform me if there is any upcoming seminar related to it.
    Thanking you.
     
  11. rockysam888

    rockysam888

    Joined:
    Jul 28, 2009
    Posts:
    650
    Hi willGoldstone,

    I am reading page 120 (just before "Attaching the script" section)
    1. I would like to know if PlayerCollisions.js is correct at this point???

    Code (csharp):
    1. private var doorIsOpen : boolean = false;
    2. private var doorTimer : float = 0.0;
    3. private var currentDoor : GameObject;
    4.  
    5. var doorOpenTime : float = 3.0;
    6. var doorOpenSound : AudioClip;
    7. var doorShutSound : AudioClip;
    8.  
    9. function Update () {
    10.     if (doorIsOpen){
    11.         doorTimer += Time.deltaTime;
    12.        
    13.         if (doorTimer > doorOpenTime) {
    14.             //shutDoor();
    15.             Door(doorShutSound, false, "doorshut", currentDoor);
    16.             doorTimer = 0.0;
    17.         }
    18.     }
    19. }
    20.  
    21. function OnControllerColliderHit(hit: ControllerColliderHit) {
    22.     if (hit.gameObject.tag == "outpostDoor"  doorIsOpen == false) {
    23.         //OpenDoor();
    24.         currentDoor = hit.gameObject;
    25.         Door(doorOpenSound, true, "dooropen", currentDoor);
    26.     }
    27. }
    28.  
    29. function OpenDoor(){
    30.     audio.PlayOneShot(doorOpenSound);
    31.     doorOpen = true;
    32.     var myOutpost : GameObject = GameObject.Find("outpost");
    33.     myOutpost.animation.Play("dooropen");
    34. }
    35.  
    36. function shutDoor(){
    37.     audio.PlayOneShot(doorShutSound);
    38.     doorIsOpen = false;
    39.    
    40.     var myOutpost : GameObject = GameObject.Find("outpost");
    41.     myOutpost.animation.Play("doorshut");
    42. }
    43.  
    44. function Door(aClip : AudioClip, openCheck : boolean, animName : String, thisDoor: GameObject){
    45.     audio.PlayOneShot(aClip);
    46.     doorIsOpen = openCheck;
    47.    
    48.     thisDoor.transform.parent.animation.Play(animName);
    49. }
    50.  
    51. @script RequireComponent(AudioSource)
    52.  
    2. Why sometimes use GameObject or gameObject for successful compilation?
    currentDoor:GameObject
    currentDoor = hit.gameObject

    3. After attaching the script to first person controller,
    why the exposed "Door Open Time" does not change to 12
    when I change it to 12 inside the script?

     
  12. Wadoman

    Wadoman

    Joined:
    Dec 8, 2007
    Posts:
    336
    @rockysam-I will try to get you started on a couple explanations as I'm not a programmer, but I understand it to some extent:

    1-I'll leave this for the more qualified

    2-currentDoor:GameObject is declaring the variable "currentDoor" to the class of "GameObject". So the value it can be assigned is only of the gameObject type. Also If im correct classes always begin in caps.
    currentDoor = hit.gameObject in this the variable "currentDoor" is being given the value of the gameObject that was hit.

    3-I believe whatever value is in the inspector is the value that it uses. If you create a variable and assign it a default value in code it will show up as that value in the inspector until you change it in the inspector. Then the variables value will always retain and use the value you assign it in the inspector even though in code it is different. The ability to change variables values in the inspector on the fly like this is very useful when testing game play.

    Well I hope this helps a little. I feel your pain though. I am slowly gaining the programming mind.
     
  13. rockysam888

    rockysam888

    Joined:
    Jul 28, 2009
    Posts:
    650
    Thank you, wadoman.
    :)

    1. I believed the code is correct as there is no problem.

    2. GameObject - class, method or component (First letter in Upper case)
    gameObject - property of object (First letter in lower case)

    3. On page 84, willGoldstone said to reset the value in inspector, we need to click the Cog icon to the right of the component and select "Reset"

    Now, I could read chapter 5.
     
  14. rockysam888

    rockysam888

    Joined:
    Jul 28, 2009
    Posts:
    650
    Hello,

    On page 158 (under section "Adding Physics")
    I use the default setting and could not see any rolls.
    What's wrong?
     
  15. Wadoman

    Wadoman

    Joined:
    Dec 8, 2007
    Posts:
    336
    It looks like you need to add a sphere collider to the coconut? Component-->Physics-->Sphere Collider
     
  16. rockysam888

    rockysam888

    Joined:
    Jul 28, 2009
    Posts:
    650
    But the book said to add Rigidbody collider on page 158. :(

    Component > Physics > Rigidbody
    (The coconut which is an ellipsoid will be used as a bullet)

    I double-checked the inspector and found that "sphere collider" is already there. (Image edited)

    Any idea?
    (or, is the word "rolls" unnecessary?)
     
  17. rockysam888

    rockysam888

    Joined:
    Jul 28, 2009
    Posts:
    650
    I don't know if the above is correct or not and continue reading.:(

    On page 166,
    However, the selection is none for coconut object.
    I am sure I already added the coconut object into Prefab as coconut prefab

    What's wrong with me?
     
  18. rockysam888

    rockysam888

    Joined:
    Jul 28, 2009
    Posts:
    650
    As a result, I dragged the "coconut prefab" into "Coconut Object" directly. Test playing is ok.



    Is this normal that "coconut prefab" could not be selected as mentioned above?
     
  19. rockysam888

    rockysam888

    Joined:
    Jul 28, 2009
    Posts:
    650
  20. boxy

    boxy

    Joined:
    Aug 10, 2005
    Posts:
    675
    Hi Will
    I just wanted to say how much I am enjoying your book. Great stuff!
    Boxy
     
  21. rockysam888

    rockysam888

    Joined:
    Jul 28, 2009
    Posts:
    650
    Hi boxy,

    Did you encounter my problem above?
     
  22. boxy

    boxy

    Joined:
    Aug 10, 2005
    Posts:
    675
    I haven't got as far as actually doing it yet. :D I'm enjoying just reading it through once first. Then I'll go back and follow through with the exercises.
    Cheers