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

Unity Game Development Essentials

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

  1. jnbutler

    jnbutler

    Joined:
    Dec 1, 2009
    Posts:
    16
    Okay, in my e-book the opacity settings in this create terrain section say 0.5, I think it is suppose to be 50 cause that is what I set mine to and my island looks like yours now. I will submit that to the errata.

    regards....
     
  2. jnbutler

    jnbutler

    Joined:
    Dec 1, 2009
    Posts:
    16
    Ok, I have found out that a lot of your settings in chapter 2 of the book are all just totally wrong. Eric5h5 in the support forum told me that tree width/height can't be lower than 50 and the variations fields can't use floats. I purchased your e-book and these things are not listed in the errata. Is there a way I could get another copy that I can at least work with?
     
  3. jnbutler

    jnbutler

    Joined:
    Dec 1, 2009
    Posts:
    16
    Okay, I have muddled through the trees and grass placements with my own settings.
    Placing the sound, and making the skybox went without a problem.
    Placing the First Person Controller went okay except that it will not move. I can look around with the mouse but the wsad keys do not move the controller.
     
  4. RHD

    RHD

    Joined:
    Mar 30, 2009
    Posts:
    719
    The controller isn't partly inside the ground or anything is it? That will stop it moving. Check it from the side and top views.
     
  5. jnbutler

    jnbutler

    Joined:
    Dec 1, 2009
    Posts:
    16
    No, that was the first thing I checked since I have experience in placing player start positions in other games editors like Hammer. But I did load the Unity Island Demo and look at the FPC in the standard assets in their demo. It has an FPSWalker script in it but the FPC in standard assets when I created the new project did not. :( So I just copied that FPSWalker script from the Unity Island demo assets folder to mine and then in the editor clicked the dropdown by the Mono(missing script) and added FPSWalker, voila' I can move in game now with WSAD keys and jump with space. :twisted:

    Moving on now I hope.... :D
     
  6. jnbutler

    jnbutler

    Joined:
    Dec 1, 2009
    Posts:
    16
    Here is a screenshot of my completed Unity Level following the instructions in Chapter 2 Environments of Unity Development Essentials by Will Goldstone.


     
  7. Patrick Hedges

    Patrick Hedges

    Joined:
    Feb 3, 2010
    Posts:
    3
    Can Someone Post the current complete code for the collision detection part of 4? Mine doesn't return any errors, but the door wont open..

    Or, would anyone mind taking a look?

    Thanks,
    Patrick
     

    Attached Files:

  8. willgoldstone

    willgoldstone

    Unity Technologies

    Joined:
    Oct 2, 2006
    Posts:
    794
    Hi Patrick

    there are finished versions of the scripts for the book in the downloadable package at packtpub.com. Let me know if you can't find it,

    Will
     
  9. Patrick Hedges

    Patrick Hedges

    Joined:
    Feb 3, 2010
    Posts:
    3
    Ok, Maybe I'll try downloading it again. For some reason, the script for chapter 4 wasn't in there, but the later chapters are...
     
  10. willgoldstone

    willgoldstone

    Unity Technologies

    Joined:
    Oct 2, 2006
    Posts:
    794
    Hey man thats because we include scripts at milestones in the book, so look at the later ones and you'll see it finished.

    Cheers
     
  11. Patrick Hedges

    Patrick Hedges

    Joined:
    Feb 3, 2010
    Posts:
    3
    I guess Im a little confused.

    Is the collision detection code combined with the Ray Casting code later in the chapter? Or does the ray casting code replace it?

    I'd really like to get the collision detection code working before I start the ray casting section.
     
  12. VeronicaG

    VeronicaG

    Joined:
    Mar 1, 2010
    Posts:
    2
    Is anyone else having trouble instantiating the coconuts in Chapter 6? My CoconutThrow.js file is giving me an error. This is the CoconutThrow.js:

    static var canThrow : boolean = false;
    var throwSound : AudioClip;
    var coconutObject : Rigidbody;
    var throwForce : float;

    function Update () {
    if(Input.GetButtonUp("Fire1") canThrow){
    audio.PlayOneShot(throwSound);
    var newCoconut : Rigidbody = Instantiate(coconutObject, transform.position, transform.rotation);
    newCoconut.name = "coconut";
    newCoconut.rigidbody.velocity = transform.TransformDirection(Vector3(0,0, throwForce));
    Physics.IgnoreCollision(transform.root.collider, newCoconut.collider, true);
    }

    }

    @script RequireComponent(AudioSource)

    The line it's having a problem with is:
    var newCoconut : Rigidbody = Instantiate(coconutObject, transform.position, transform.rotation);

    and the error it's giving is:
    InvalidCastException: Cannot cast from source type to destination type. at CoconutThrow.Update ()
     
  13. marcos

    marcos

    Joined:
    Oct 18, 2009
    Posts:
    592
    My copy just arrived, let's see if you can turn a 3d artist into a game developer, eh?

    :D
     
  14. rockysam888

    rockysam888

    Joined:
    Jul 28, 2009
    Posts:
    650
  15. willgoldstone

    willgoldstone

    Unity Technologies

    Joined:
    Oct 2, 2006
    Posts:
    794
    Hi Veronica

    your code looks okay so odd that you have that error. The error you've pasted there is telling you that you are casting between two types. What this means in simple terms is that when you establish a variable, you give it a data type, and Unity then expects it to contain certain classes / parameters based upon that. This would occur if you wrote a data type for an object at the top of your script as a member variable and then a completely different type when you tried to instantiate it. As you have written 'Rigidbody' as the data type in both parts of your script it *should* be fine.. so.. not sure what has happened. Any problems you get with the book there are a few typos we missed in the final edit so just check the 'Errata' section on the packtpub.com

    Hope you enjoy the book ^_^

    Will
     
  16. rouhee

    rouhee

    Joined:
    Dec 23, 2008
    Posts:
    194
    Here is some of my thoughts. The book itself contains good tutorials for basic game making with Unity. However, I was little disapointed for the Javascript.
    I would have personally recommend C# for everyone who is starting to make code for games. But as I said, good book for beginners.

    I'll give it 4 out of 5.


    Cheers--
     
  17. willgoldstone

    willgoldstone

    Unity Technologies

    Joined:
    Oct 2, 2006
    Posts:
    794
    Rouhee,

    Thanks! I had wondered what you thought ;) anyway, I chose JS as it is more accessible in some ways for those migrating from web development and easier to compare with Unity's own documentation as a multitude of the examples are in JS, so to me it made sense, but as i've said before there isn't a massive leap to understanding C# syntax once you have nailed how Unity works and got your heading around the available classes.

    Cheers

    Will
     
  18. rockysam888

    rockysam888

    Joined:
    Jul 28, 2009
    Posts:
    650
  19. willgoldstone

    willgoldstone

    Unity Technologies

    Joined:
    Oct 2, 2006
    Posts:
    794
    Hi rockysam

    you would cast a ray ahead of the coconut using Physics.Raycast. This technique is covered in the door opening part of the book.

    This would mean a ray would constantly stick out ahead of the coconut and could therefore tell you if you'd missed something.

    You would also need to tick 'freeze rotation' on the rigidbody of the coconut to do this, because otherwise the ray would be spinning with the coconut.
     
  20. rockysam888

    rockysam888

    Joined:
    Jul 28, 2009
    Posts:
    650
    Thank you, willGoldstone. I will try again later. :)
     
  21. imabadfish

    imabadfish

    Joined:
    Mar 4, 2010
    Posts:
    3
    I followed the instructions in the book as well as looking at this thread in regards to chapter 4 but still have these issues.

    I keep getting an error stating "the best overload for the method is not compatible with the argument list.

    Also when I add the script the the first person controller object the public variables do not appear (AudioClips)

    Lastly the @script RequireComponent(AudioSource) does not seem to be working either.. as in it doesn't automatically ad the audio component when the script is added.

    Any help or if some one has code that worked for them please post it up

    Thanks


    My code
    Code (csharp):
    1.  
    2. private var doorIsOpen : boolean = false;
    3. private var doorTimer : float = 0.0;
    4.  
    5. var doorOpenSound : AudioClip;
    6. var doorShutSound : AudioClip;
    7.  
    8. function OnControllerColliderHit (hit:ControllerColliderHit){
    9.     if(hit.gameObject.tag == "outpostDoor"  doorIsOpen == false){
    10.         Door(doorOpenSound, true, "dooropen");
    11.     }
    12. }
    13.  
    14. function Update () {
    15. if(doorIsOpen){
    16.     doorTimer += Time.deltaTime;
    17.    
    18.     if(doorTimer > 3){
    19.     Door(doorShutSound, false, "doorshut");
    20.         doorTimer = 0.0;
    21.         }
    22.     }
    23. }
    24.  
    25.  
    26.  
    27. function Door(aClip : AudioClip, openCheck : boolean, animName :
    28. String) {
    29.     audio.PlayOneShot(aClip);
    30.     doorIsOpen = openCheck;
    31.     var myOutpost : GameObject = GameObject.Find("outpost");
    32.     myOutpost.animation.Play(animName);
    33. }
    34. @script RequireComponent (AudioSource)
    35.  
     
  22. VeronicaG

    VeronicaG

    Joined:
    Mar 1, 2010
    Posts:
    2
    Will,

    Thanks for the reply and I'm really enjoying the book.

    Yeah, I'm not sure what's going on with my code/level from Chapter 6. I noticed another thing that was off was when I connected the CoconutThrow script up to the Launcher, the options for Coconut Object were not the same. For example, (on page 166) Coconut Object is one of the public member variables that needs to be assigned an asset, but when I click on the drop down menu Coconut Prefab is not an option. In fact, there is nothing when I click on the drop down menu.

    I might just try redoing the chapter if nothing else I try fixes it.

    Thanks again for the reply.
     
  23. imabadfish

    imabadfish

    Joined:
    Mar 4, 2010
    Posts:
    3
    Got the Ray Casting method working at least. That seems better for First Person style anyway.
     
  24. imabadfish

    imabadfish

    Joined:
    Mar 4, 2010
    Posts:
    3
    Chapter 6 Issue

    I created the Launcher and the components that show up are Transform, Audio Source, and Coconut Throw (Script)

    I can set the throw sound and the throw force easily, but the Coconut Object selection shows nothing, as in I can;t select the coconut prefab.

    I went through the coconut making process again and still can't manage to select on the Launcher...

    Any one else run into this or know how to solve it?
     
  25. Jessw14

    Jessw14

    Joined:
    Jan 31, 2010
    Posts:
    14
    I am trying to complete Chapter Four in the book but I am having a problem. The door will open with sound, but when it goes to shut all I hear is the sound but the door remains open.

    I am a newbie to scripting and cannot seem to figure out what the problem is. It is probably something so simple that I will never notice or just overlook completely. I appreciate everyone on these boards for all your help and patience. My script is posted below.

    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.  
    11.     if(doorIsOpen){
    12.         doorTimer += Time.deltaTime;
    13.        
    14.         if(doorTimer > 3){
    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.         currentDoor = hit.gameObject;
    24.         Door (doorOpenSound, true, "dooropen", currentDoor);
    25.     }
    26. }
    27.  
    28. function Door (aClip : AudioClip, openCheck : boolean, animName : String, thisDoor : GameObject){
    29.     audio.PlayOneShot (aClip);
    30.     doorIsOpen = openCheck;
    31.    
    32.     thisDoor.transform.parent.animation.Play(animName);
    33. }
    34.  
    35. @script RequireComponent (AudioSource)
     
  26. Jessw14

    Jessw14

    Joined:
    Jan 31, 2010
    Posts:
    14
    Never mind I figured it out! It was so simple and stupid at the same time. I just forgot to set the doorshut animation in the inspector panel.
     
  27. wyel

    wyel

    Joined:
    Apr 4, 2010
    Posts:
    1
    Hi! I'm also having an error in chapter 6 when I instantiate the coconut.

    The error is: InvalidCastException: Cannot cast from source type to destination type.

    Just like VeronicaG, the line that causes the error is:
    Code (csharp):
    1. var newCoconut : Rigidbody = Instantiate(coconutObject, transform.position, transform.rotation);
    I can't find the cause of this...:? Any help on this?

    Oh, and the book is great so far, by the way :D

    EDIT***
    Ok I tried to replace the newCoconut data type from Rigidbody to GameObject and it seems to work pretty well. Maybe it has something to do with the Unity version? If anyone knows why it is that way, I'm still curious to know the reason :wink:
     
  28. rockysam888

    rockysam888

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

    On page 143 of chapter 4,
    "BatteryGUI" already is GUITexture component.
    GameObject.Find("Battery GUI") should return the GUITexture component. Why bother to use another GetComponent(GUITexture)? Why not directly use:

    GameObject.Find("Battery GUI").enabled=false;

    ???
     
  29. alzan12

    alzan12

    Joined:
    Apr 6, 2010
    Posts:
    71
    i have an error in my scripting and i want to fix it but the code for ch4 is not here.
     
  30. rockysam888

    rockysam888

    Joined:
    Jul 28, 2009
    Posts:
    650
  31. rockysam888

    rockysam888

    Joined:
    Jul 28, 2009
    Posts:
    650
    @alzan12:Show us your code.
     
  32. alzan12

    alzan12

    Joined:
    Apr 6, 2010
    Posts:
    71
    ok here is the code:

    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.  
    7. var doorOpenSound : AudioClip;
    8.  
    9. var doorShutSound : AudioClip;
    10.  
    11. function Update () {
    12.     if(doorisOpen){
    13.             doorTimer += Time.deltaTime;
    14.     }
    15.    
    16.     if(doorTimer > 3){
    17.        Door(doorShutSound, false, "doorshut", currentDoor) ;
    18.        doorTimer = 0.0;
    19.        
    20.     }
    21. }
    22.  
    23. function OnControllerColliderHit (hit : ControllerColliderHit) {
    24.      if(hit.gameObject.tag == "outpostDoor"  doorisOpen == false){
    25.          currentDoor = hit.gameObject;
    26.          Door(doorOpenSound, true, "dooropen", currentDoor);
    27.      }
    28. }
    29.  
    30.  
    31.  
    32. function Door(aClip : AudioClip, openCheck : boolean, animName : String, thisDoor : GameObject){
    33.    audio.PlayOneShot (aClip);  
    34.    doorisOpen = openCheck;
    35.    
    36.    thisDoor.transform.parent.animation.Play(animName);
    37.    Door(doorShutSound, true, "doorshut", currentDoor);
    38. }
    39. @script RequireComponent (AudioSource)



    thats the playerCollisions script for the door.
    I hit it, then it "delays", and then the door opens, then "unity quits".
     
  33. rockysam888

    rockysam888

    Joined:
    Jul 28, 2009
    Posts:
    650
    It "delays" because you just created a recusion(Function door call door again)

    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 = 12.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 Door(aClip : AudioClip, openCheck : boolean, animName : String, thisDoor: GameObject){
    30.     audio.PlayOneShot(aClip);
    31.     doorIsOpen = openCheck;
    32.    
    33.     thisDoor.transform.parent.animation.Play(animName);
    34. }
    35.  
    36. @script RequireComponent(AudioSource)
    37.  
     
  34. alzan12

    alzan12

    Joined:
    Apr 6, 2010
    Posts:
    71
    ty it works but it colses about 7/8 of the way. then it stops. is that something in the script? or is it the animation?
     
  35. rockysam888

    rockysam888

    Joined:
    Jul 28, 2009
    Posts:
    650
    For current version v2.6.1, after you saved your scripts and if there is something wrong with your scripts, there is always a error message that informs you what's wrong, just under the scene editor.

    What is that error message, alzan12? Could you post it here too?
     
  36. alzan12

    alzan12

    Joined:
    Apr 6, 2010
    Posts:
    71
    sorry for all the probs im new to javascript :eek: . i have a new prob. here it is. :arrow:

    error :
    :!:

    error 2 :eek: :
    :!:
    script: :arrow:
    Code (csharp):
    1. var batteryCollect : AudioClip;
    2. private var doorIsOpen : boolean = false;
    3. private var doorTimer : float = 0.0;
    4. private var currentDoor : GameObject;
    5.  
    6. var doorOpenTime : float = 3.0;
    7. var doorOpenSound : AudioClip;
    8. var doorShutSound : AudioClip;
    9.  
    10.  
    11.  
    12. function Update(){
    13.    
    14.     var hit : RaycastHit;
    15.  
    16.     if (Physics.Raycast (transform.position, transform.forward, hit, 3)) {
    17.         if(hit.collider.gameObject.tag=="outpostDoor"  doorIsOpen == false  BatteryCollect.charge >= 4){Door(doorOpenSound, true, "dooropen");
    18.             GameObject.Find("Battery GUI").GetComponent(GUITexture).enabled=false;
    19.         }else if(hit.collider.gameObject.tag=="outpostDoor"  doorIsOpen == false  BatteryCollect.charge < 4){
    20.             GameObject.Find("Battery GUI").GetComponent(GUITexture).enabled=true;  
    21.             TextHints.message = "the door makes a funny sound like it`s trying to open";
    22.             TextHints.textOn = true;
    23.         }
    24.     }
    25.  
    26.    
    27.     if(doorIsOpen){
    28.         doorTimer += Time.deltaTime;
    29.        
    30.         if(doorTimer > 3){
    31.             Door(doorShutSound, false, "doorshut");
    32.             doorTimer = 0.0;
    33.         }
    34.     }  
    35. }
    36.  
    37.  
    38.  
    39.  
    40.  
    41. function Door(aClip : AudioClip, openCheck : boolean, animName : String, thisDoor : GameObject){
    42.     audio.PlayOneShot(aClip);
    43.     doorIsOpen = openCheck;
    44.     thisDoor.transform.parent.animation.Play(animName);
    45.  
    46. }
    47.  
    48. /*
    49.  
    50. function OnControllerColliderHit(hit: ControllerColliderHit){
    51.     if(hit.gameObject.tag == "outpostDoor"  doorIsOpen == false){
    52.         currentDoor = hit.gameObject;
    53.         Door(doorOpenSound, true, "dooropen", currentDoor);
    54.     }
    55. }
    56.  
    57. */
    58.  
    59.  
    60. function OnTriggerEnter(collisionInfo : Collider){
    61.     if(collisionInfo.gameObject.tag == "battery"){
    62.         BatteryCollect.charge++;
    63.         audio.PlayOneShot(batteryCollect);
    64.         Destroy(collisionInfo.gameObject); 
    65.     }
    66. }
    67.  
    68.  
    69. @script RequireComponent(AudioSource)
    :)
     
  37. rockysam888

    rockysam888

    Joined:
    Jul 28, 2009
    Posts:
    650
    Code (csharp):
    1. function Update(){
    2.    
    3.    var hit : RaycastHit;
    4.  
    5.    if (Physics.Raycast (transform.position, transform.forward, hit, 3)) {
    6.       if(hit.collider.gameObject.tag=="outpostDoor"  doorIsOpen == false  BatteryCollect.charge >= 4){Door(doorOpenSound, true, "dooropen");
    7.          GameObject.Find("Battery GUI").GetComponent(GUITexture).enabled=false;
    8.       }else if(hit.collider.gameObject.tag=="outpostDoor"  doorIsOpen == false  BatteryCollect.charge < 4){
    9.          GameObject.Find("Battery GUI").GetComponent(GUITexture).enabled=true;  
    10.          TextHints.message = "the door makes a funny sound like it`s trying to open";
    11.          TextHints.textOn = true;
    12.       }
    13.    }
    14.  
    15.    
    16.    if(doorIsOpen){
    17.       doorTimer += Time.deltaTime;
    18.      
    19.       if(doorTimer > 3){
    20.          Door(doorShutSound, false, "doorshut");
    21.          doorTimer = 0.0;
    22.       }
    23.    }  
    24. }
    25.  
    1. Please check for typing mistake, letter by letter. (Some near the "Door"...)
    2. What is the name of your battery object? They must be the same throughout the whole project!
    Is it "BatteryGUI", "Battery GUI" or "battery GUI", etc.? (The case and spacing of the name matters. Unity thinks they refer different objects)
     
  38. alzan12

    alzan12

    Joined:
    Apr 6, 2010
    Posts:
    71
    Code (csharp):
    1. var batteryCollect : AudioClip;
    2. private var doorIsOpen : boolean = false;
    3. private var doorTimer : float = 0.0;
    4. private var currentDoor : GameObject;
    5.  
    6. var doorOpenTime : float = 3.0;
    7. var doorOpenSound : AudioClip;
    8. var doorShutSound : AudioClip;
    9.  
    10.  
    11.  
    12. function Update(){
    13.    
    14.    var hit : RaycastHit;
    15.  
    16.    if (Physics.Raycast (transform.position, transform.forward, hit, 3)) {
    17.    
    18.       if(hit.collider.gameObject.tag=="outpostDoor"  doorIsOpen == false  BatteryCollect.charge >= 4){
    19.      
    20.          Door (doorOpenSound, true, "dooropen", currentDoor);
    21.      
    22.  
    23.          GameObject.Find("Battery GUI").GetComponent(GUITexture).enabled=false;
    24.          
    25.       }else if(hit.collider.gameObject.tag=="outpostDoor"  doorIsOpen == false  BatteryCollect.charge < 4){
    26.      
    27.          GameObject.Find("Battery GUI").GetComponent(GUITexture).enabled=true;    
    28.          
    29.          TextHints.message = "the door makes a funny sound like it`s trying to open";
    30.          
    31.          TextHints.textOn = true;
    32.       }
    33.    }
    34.  
    35.    
    36.    if(doorIsOpen){
    37.       doorTimer += Time.deltaTime;
    38.      
    39.       if(doorTimer > 3){
    40.          Door (doorShutSound, false, "doorshut",currentDoor);
    41.          doorTimer = 0.0;
    42.       }
    43.    }    
    44. }
    45.  
    46.  
    47.  
    48.  
    49.  
    50. function Door(aClip : AudioClip, openCheck : boolean, animName : String, thisDoor : GameObject){
    51.    audio.PlayOneShot(aClip);
    52.    doorIsOpen = openCheck;
    53.    thisDoor.transform.parent.animation.Play(animName);
    54.  
    55. }
    56.  
    57. /*
    58.  
    59. function OnControllerColliderHit(hit: ControllerColliderHit){
    60.    if(hit.gameObject.tag == "outpostDoor"  doorIsOpen == false){
    61.       currentDoor = hit.gameObject;
    62.       Door(doorOpenSound, true, "dooropen", currentDoor);
    63.    }
    64. }
    65.  
    66. */
    67.  
    68.  
    69. function OnTriggerEnter(collisionInfo : Collider){
    70.    if(collisionInfo.gameObject.tag == "battery"){
    71.       BatteryCollect.charge++;
    72.       audio.PlayOneShot(batteryCollect);
    73.       Destroy(collisionInfo.gameObject);    
    74.    }
    75. }
    76.  
    77.  
    78. @script RequireComponent(AudioSource)
    fixt it but now a new error comes up saying:
    and the door wall make the sound of it opening over an over non stop like tttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttt.
     
  39. alzan12

    alzan12

    Joined:
    Apr 6, 2010
    Posts:
    71
    nvm i fixt it. but if you see anything else pleese tell me
     
  40. alzan12

    alzan12

    Joined:
    Apr 6, 2010
    Posts:
    71
    how do you add a delay time
     
  41. imaginaryhuman

    imaginaryhuman

    Joined:
    Mar 21, 2010
    Posts:
    5,834
    I haven't been following the discussion but I wanted to mention that I did buy the Essentials book and enjoyed it a lot. Took me a few days to get through it but the experience was worthwhile. Everything is well explained and there is barely any time where something is assumed without being explained in proper detail, it's very well done and aimed at people who are fairly new to Unity, which I was/am. The skills learned are more important than the end product, of course, so that you can transfer to starting to make your own games and creations, and I would certainly recommend this book to anyone who hasn't bought it yet. Even though I had read through much of the online material and did the 2d platformer tutorial I still learned a lot of new stuff in this book.



    It seems now that Unity needs a book for advanced use which goes beyond this book and covers things like shaders, animation, modelling, more advanced physics etc. Perhaps we'll see that someday.
     
  42. dapeeper

    dapeeper

    Joined:
    Apr 28, 2010
    Posts:
    14
    Has anyone finally found the problem with the outpost door not closing fully?

    I tried it again recently with 2.61 and the door opens fine but after the 3 seconds delay, it does not close fully all the time. Sometimes it closes fully but mostly there is a gap after it closes. And sometimes the gap is huge. See images.

    Appears to be some sort of timing issue.

    Both images are after calling the ShutDoor function. OpenDoor works fine.
    Here is my code:

    //*******************************************************
    function OpenDoor()
    {
    audio.PlayOneShot(doorOpenSound);
    doorIsOpen = true;
    var myOutpost : GameObject = GameObject.Find("outpost");
    myOutpost.animation.Play("dooropen");

    }
    //*********************************************************
    function ShutDoor()
    {
    audio.PlayOneShot(doorShutSound);
    doorIsOpen = false;
    var myOutpost : GameObject = GameObject.Find("outpost");
    myOutpost.animation.Play("doorshut");

    }
     

    Attached Files:

  43. mojojojo

    mojojojo

    Joined:
    Dec 16, 2009
    Posts:
    138
    I've got a question on a semi-related topic. I just got the book a week ago and are working through the tuts. In the book we assign dooropen and doorshut in the animations and add a frame difference to them. The book doesn't explain what adding the frames does nor does it explain how adding doorshut produces an animation.

    A. Is doorshut a set animation within inherent to Unity that it knows what to do? What dictates the door's movement? It would seem to me I'd have to set up an animation (3dsmax style) and apply that as the animation for doorshut but somehow it already knows what to do. What am I missing?

    B. What's up w/ the frame numbering. The book says to have 3 animations like so.
    idle fr 1-2
    dooropen fr 3-12
    doorshut fr 13-24

    I don't have a clue why these need designations or what's happening here. If it's a time for the door to open or shut why wouldn't I just have a number of frames it takes to perform the animation?

    Any help would be greatly appreciated.
     
  44. Unearthly

    Unearthly

    Joined:
    Jul 2, 2010
    Posts:
    4
    Hello. I've just finished going through the book and it was very helpful as an introduction to Unity. One thing I wanted to ask about was the included outpost model. It is very easy to get completely stuck on the walls or posts on the outpost. Does this happen for others? Are there ways to prevent this from happening?
     
  45. Monty

    Monty

    Joined:
    Sep 26, 2009
    Posts:
    30
    ungoliath You were almost there in your thought process. The frame numbering refers the the animation that was set up in Cinema4D. So in C4D Will made an animation of a door opening and closing.Then he simply referred to the specific parts of that animation in Unity with idle 0 to 5, open 6 to 10 etc.

    If you think bigger you can apply this thinking to character animation. In your 3d Program you animate a model and on the time frame 0 to 10 might be idle, 11 to 20 might be running. Then you just refer the the relevant parts in your script and then presto.

    Actually Unity has some limited animation tools (introduced I think after Will wrote the book) which allow simple animation like doors and the such but you can research that for yourself. It's called the Animation Curve Editor.
     
  46. Monty

    Monty

    Joined:
    Sep 26, 2009
    Posts:
    30
    dapeeper yes lots of us had that problem :) The problem, I think, is fully on Wills part so direct your scorn and hatred at him :evil: I could never be bothered to fix it but I'm sure either tweaking the animation frame numbers or just going into your own 3d program and animating it yourself will fix the little problem.
     
  47. mojojojo

    mojojojo

    Joined:
    Dec 16, 2009
    Posts:
    138
    Thanks Monty but I'm not certain I've got this completely straight. I use 3ds max so I don't know if things work differently with Cinema 4d.
    A. I create models in 3ds max, Cinema 4d etc.
    B. I animate those models in a certain fashion and name those animations.
    C. Import into Unity and when I name a new animation that title must be identical to what it was named in my modeling tool.
    D. I add frame numbers to designate how fast that animation plays.
     
  48. Monty

    Monty

    Joined:
    Sep 26, 2009
    Posts:
    30
    Close but no cigar :)

    Most 3d programs operate in a similar way, 3ds max and cinema4d are two such programs.

    No you don't name the animations in the 3d program, you just need to animate on the time-line and then save. You name the parts of the animation you want using Unity but to reference what parts of an objects animation you want you just provide unity with the relevant frame numbers.
     
  49. mojojojo

    mojojojo

    Joined:
    Dec 16, 2009
    Posts:
    138
    Awesome, that makes sense now.
     
  50. fulcanmal

    fulcanmal

    Joined:
    Aug 7, 2010
    Posts:
    25
    I skimmed through all the posts, so I apologize if I missed anyone else who already mentioned this problem.

    I downloaded the resources but when I go to Import Package>Sound1 I just get a 'ding' sound and nothing happens.

    I've also had the following error at the bottom of my screen ever since I opened a new project:

    'TargetInvocationException: Exception has been thrown by the target of an invocation.'

    Can anyone help?