Search Unity

Unity Game Development Essentials

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

  1. Chris Aoki

    Chris Aoki

    Joined:
    Jan 15, 2012
    Posts:
    200
    Here you go, have fun!

    http://dl.dropbox.com/u/42597431/GDE3xTerrain.unitypackage
     
  2. OMG!Yeti's

    OMG!Yeti's

    Joined:
    Jan 9, 2012
    Posts:
    27
  3. roto23

    roto23

    Joined:
    Oct 30, 2009
    Posts:
    240
    You probably already know about this site, but it can't hurt if I repost it. Just select your book title from the drop down.


    http://www.packtpub.com/support
     
  4. vdek

    vdek

    Joined:
    Sep 2, 2011
    Posts:
    368
  5. cmartin81

    cmartin81

    Joined:
    Mar 8, 2012
    Posts:
    2
    Hello, I´ve just bought a copy of the book. Great book so far!!
    My problem is that I can´t import the asset package. When I unzip the file I get a "book_assets.unitypackage.zip". After renaming it to "book_assets.unitypackage" and trying to import it in unity i get the following error message:
    Error while importing package: Package has unknown format.

    I´ve got the latest unity and I´m working on a mac. What should I do?
     
  6. roto23

    roto23

    Joined:
    Oct 30, 2009
    Posts:
    240
    Download the zip file again. It should unzip to a usable file system.
     
  7. darthbator

    darthbator

    Joined:
    Jan 21, 2012
    Posts:
    169
    I was having the same error cmartin81 was having until I noticed what the OS is doing. The default archive util in OSX seeks to fully "inflate" a file from packaging. For some reason when you try to inflate the book_assets.unitypackage.zip package it ALSO extracts the .unitypackage into a system folder (book assets). You can actually see the system doing this and if you press cancel after it has extracted the first volume you'll be left with the package file you need to import into untiy!
     
  8. cmartin81

    cmartin81

    Joined:
    Mar 8, 2012
    Posts:
    2
    Thanks darthbator!
    It worked!
    I had to cancel the operation after unzipping "book_assets.unitypackage.zip".

    Great I can finally continue my learning!
    Have a great weekend!
     
  9. iJoshJenkins

    iJoshJenkins

    Joined:
    Mar 20, 2012
    Posts:
    1
    My code for the CoconutThrow is
    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)

    However when i stand on the mat i cant throw coconuts, i have redone all the scripts over and over but i still can seem to either set the throwForce variable like it says in the book or throw coconuts at all for that matter.

    Any help would be much appreciated
     
  10. maawaa

    maawaa

    Joined:
    Apr 1, 2012
    Posts:
    16

    my velocity code in the book is different to that, i have

    newCoconut.velocity = transform.forward * throwSpeed;


    also, make sure cocnut shy "mat" box collider has the script assigned to it
     
  11. maawaa

    maawaa

    Joined:
    Apr 1, 2012
    Posts:
    16
    Hi there, i have been going through the newest edition (3.x) of this book, and up to chapter 8 it is to be frank absolutely amazing. It is one of the best "learn as you go" books i have read, so kudos to the writters.


    My problems started at chapter 8 with the particle systems which are completely different. It isnt the authors problem really as it all changed in the last release (i think?), but the entire chapter needs throwing out and re-writing from scratch to be honest as it just confused the hell out of me.

    In the end i managed to make my way through by using the new style emitters and just playing with the numbers for what seemed like ages (it looks a bit rubbish but it 'works').

    That then meant the code for reactivating the emitters on the camp fire no longer worked. Fortunately im a .net programmer so knew how to work my way back to the new object names and go from there.

    in the end i rewrote the code to use ParticleSystem instead of ParticleEmitter

    Code (csharp):
    1.  
    2. void LightFire(GameObject campfire)
    3.     {
    4.         ParticleSystem[] fireEmitters;
    5.         fireEmitters = campfire.GetComponentsInChildren<ParticleSystem>();
    6.        
    7.         foreach(ParticleSystem emitter in fireEmitters)
    8.         {
    9.             emitter.enableEmission=true;
    10.         }
    11.        
    12.         campfire.audio.Play();
    13.         Destroy(matchGUI);
    14.         haveMatches=false;
    15.         fireIsLite=true;
    16.     }
    17.  
    my main question is, is this the right way to do it???

    I dont want to get my head into doing it this way if it is wrong or has repurcussions later in more complicated games...
     
  12. willgoldstone

    willgoldstone

    Unity Technologies

    Joined:
    Oct 2, 2006
    Posts:
    794
    Hi there, first off thanks for buying the book and thank you very much for the praise, glad you like it.

    As for chapter 8 - yes this was released before the new particle system in 3.5. What I plan to do is make a video tutorial that covers making the fire and also the code that occurs later to enable / disable it.

    For now, what I will do is post a new part on the support site 'Unitybook.net' with details on how best to rewrite the code. Sorry for the delay in providing you this info! Any further problems, feel free to write to me - will at unity3d.com.

    All the best

    Will
     
  13. darthbator

    darthbator

    Joined:
    Jan 21, 2012
    Posts:
    169
    I was wondering if there was an ETA on the video explaining the newer particle system? That happens to be right where I am in the book right now and I'm having a rough time getting something that I think looks right out of the new "ParticleSystem" in unity 3.5. I was thinking about just following the instructions I saw in the comments of the book site and instantiating the legacy system but I would love to just learn the new one. Just thought I would toss a feeler out there and see how soon that might get done.

    Outside of this one minor issue I find the book to be extremely helpful and to the point!
     
  14. Matteo Zanetti

    Matteo Zanetti

    Joined:
    Apr 6, 2012
    Posts:
    2
    Hi Will,

    I am having an issue while throwing the coconuts using Unity 3.5.0f5, since the fire1 button seems to be too much sensitive on click.
    So when I click on the left mouse button ( or I press on left ctrl ) the result is an huge amount of coconuts fired ( I had the same issue on the Shooter example ).

    In order to solve it I have added a timer inside the Update function of the CoconutThrower, so only a coconut is thrown inside a limited fraction of time.

    Code (csharp):
    1. float timer = 0.0f;
    2.    
    3. // Update is called once per frame
    4. void Update () {
    5.     if(Input.GetButton("Fire1")){
    6.         if(timer == 0.0f){
    7.             audio.PlayOneShot(throwSound);
    8.             Rigidbody newCoconut = Instantiate(coconutPrefab, transform.position, transform.rotation) as Rigidbody;
    9.             newCoconut.name = "coconut";
    10.             newCoconut.velocity = transform.forward * throwSpeed;
    11.             timer = timer + Time.deltaTime;
    12.         }
    13.         else if (timer >= 0.1f){
    14.             timer = 0.0f;
    15.         }
    16.         else{
    17.             timer = timer + Time.deltaTime;
    18.         }
    19.    
    20.     }
    21. }
    I am wondering if instead of manage it through the script it is possible to solve it simply by changing a setting in Unity.

    By the way the book is amazing!

    Matteo
     
  15. Matteo Zanetti

    Matteo Zanetti

    Joined:
    Apr 6, 2012
    Posts:
    2
    My mistake I used Input.GetButton instead of Input.GetButtonDown!
     
  16. willgoldstone

    willgoldstone

    Unity Technologies

    Joined:
    Oct 2, 2006
    Posts:
    794
    It's done! -

    http://unitybook.net/updates-to-unity-3/
     
  17. maawaa

    maawaa

    Joined:
    Apr 1, 2012
    Posts:
    16
    oh happy days! cheers Will!
     
  18. rockysam888

    rockysam888

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

    First of all, the new version of book is worth buying.

    On page 178 of new version,
    Why could we simply write
    ?


    I found an old thread said:
    http://forum.unity3d.com/threads/131693-SendMessage-vs-direct-function-calls?highlight=sendmessage
    Thanks in advance
     
    Last edited: Apr 20, 2012
  19. Batzarro

    Batzarro

    Joined:
    Apr 22, 2012
    Posts:
    51
    Hi. I've come from my thread here;

    http://forum.unity3d.com/threads/133974-Complete-C-(sharp)-beginner-Any-tips-on-learning

    I've read through all the posts on this thread, but nothing is mentioned about anything before Chapter 2, so I didn't find anyone with my problems. Like I said in my thread above, I'm new to this, I'm essentually terrible at understanding any of chapter 1. But I decided to just keep going on, even though I mostly didn't understand all the code/script talk. Yeah, I'm just incredibly dumb, I just don't get it, sorry. Basically I'm stuck right at the start, where you begin to make the C# (sharp) script called 'Shooter'.

    On page 68, it says to copy the "code snippet into your script", so I did that and it was fine.
    Code (csharp):
    1. using UnityEngine;
    2. using System.Collections;
    3. public class Shooter : MonoBehaviour {
    4.     public Rigidbody bullet;
    5.     public float power = 1500f;
    6.     public float moveSpeed = 2f;
    7.  
    8.     void Update () {
    9.     }
    10. }
    Then I assign it to the 'Main Camera'. Then on page 72, this is written; "Because Input is also the name of a class, and all named elements in the Input Manager are axes or buttons, in scripting terms we can simply use:
    Code (csharp):
    1. Input.GetAxis("Horizontal");
    This is where it all started to go wrong for me. Originally, I assumed I didn't have to copy this code into the script because it doesn't say anything like "copy this snippet". Some more code is mentioned for a couple more pages, and then just before I'm told to test the game (by pressing play), it does give me some code and says I need to copy it. So I copied it, but errors came up all over the place, so it wouldn't play. So I went back to the start, where the book mentioned the code;
    Code (csharp):
    1. Input.GetAxis("Horizontal");
    So I think, OK, all this stuff before the "test", I'm supposed to copy it into the script. But it doesn't say where to insert it, so I guessed;
    Code (csharp):
    1. using UnityEngine;
    2. using System.Collections;
    3. public class Shooter : MonoBehaviour {
    4.     public Rigidbody bullet;
    5.     public float power = 1500f;
    6.     public float moveSpeed = 2f;
    7.     Input.GetAxis("Horizontal");
    8.  
    9.     void Update () {
    10.     }
    11. }
    Nope. The new line, 'Input.GetAxis("Horizontal");', has a red error line under it. So I cut and paste it so that it's after 'void Update () {'. No red line comes up, so that's good, even though it doesn't tell me to add anything to that section until further down. So I went on until I got to;
    Code (csharp):
    1. void Update () {
    2. float h = Input.GetAxis("Horizontal") * Time.deltaTime *
    3. moveSpeed;
    4. float v = Input.GetAxis("Vertical") * Time.deltaTime * moveSpeed;
    I added this to under the last one I added, but got a red line under 'void Update () {'. SO I started all over again, and didn't add anything until page 74 where I'm asked to "Place the given line within the Update() function in your script; - meaning after the opening curly brace of Update(){ and before the function closes with a right curly brace }". That code was;
    Code (csharp):
    1. transform.Translate(h, v, 0);
    But that didn't work either, so I'm doing it all wrong. I don't understand when I'm supposed to copy the code, and where I'm supposed to put it, I'm so confused. I know it's simple stuff, and the book is good, but I wish there was a book that was actually for people who don't know anything about C# and/or JavaScript. Sorry for the long, step by step mssg, actually did it so that I could go through it myself again, page by page, to see what I did wrong.

    Any help would be great. Thanks.
     
    Last edited: May 7, 2012
  20. rockysam888

    rockysam888

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

    Code (csharp):
    1. using UnityEngine;
    2. using System.Collections;
    3. public class Shooter : MonoBehaviour {
    4. public Rigidbody bullet;
    5. public float power = 1500f;
    6. public float moveSpeed = 2f;
    7.  
    8. void Update () {
    9. float h = Input.GetAxis("Horizontal") * Time.deltaTime *
    10. moveSpeed;
    11. float v = Input.GetAxis("Vertical") * Time.deltaTime * moveSpeed;
    12. transform.Translate(h, v, 0);
    13. }
    transform.Translate(h, v, 0) need the value variable h and v, so it is logical to place it at the end.
    If this statement was put before float h or v, value h or v of is zero. No translation results.It is meaningless to get value h and v later because they are not used at all.

    Code (csharp):
    1. void Update () {
    2. transform.Translate(h, v, 0);   // value of h and v maybe 0
    3.  
    4. float h = Input.GetAxis("Horizontal") * Time.deltaTime *
    5. moveSpeed;
    6. float v = Input.GetAxis("Vertical") * Time.deltaTime * moveSpeed;
    7. // value of h and v are not used
    8. }
    Besides when you work through the book, Please look for update and errors of the book too.
    http://unitybook.net/updates-to-unity-3/
    http://unitybook.net/book-errata/
     
    Last edited: May 3, 2012
  21. hdfreema

    hdfreema

    Joined:
    May 2, 2012
    Posts:
    5
    I'm on Chapter 4 and have the same problem as another fellow, where the First Person Controller just ran right through the door and never triggered the collider. I re-placed them in the scene, being sure that "generate colliders" was checked. Still no go... any other thoughts what could do this?

     
    Last edited: May 5, 2012
  22. hdfreema

    hdfreema

    Joined:
    May 2, 2012
    Posts:
    5
    Okay, never mind, I'm an idiot. I had a beer and it solved all my problems... My beer pointed out that "Is Trigger" was checked for the door's box collider. Viva la homebrew.
     
  23. D2R1000

    D2R1000

    Joined:
    May 30, 2012
    Posts:
    1
    Hi all,

    I have been going through the newest edition of the book and have completed Chapter 12 - Building and Sharing.

    In the section "Adapting for web build/preparing for streaming," the main menu GUI script is modified to display loading progress by replacing the play button with a message. When the load percentage reaches 100%, the play button is supposed to be swapped back in. I cannot figure out what I have overlooked. Attached is the script function from the chapter.

    Code (csharp):
    1. function OnGUI() {
    2.  
    3.     GUI.skin = menuSkin;
    4.     GUI.BeginGroup (menuAreaNormalized);
    5.     if(menuPage == "main"){
    6.    
    7.         if(Application.CanStreamedLevelBeLoaded("Island")){
    8.             if(GUI.Button(Rect(playButton), "Play")){
    9.                 ButtonAction("Island");
    10.             }else{
    11.                 var percentLoaded : float =
    12.                     Application.GetStreamProgressForLevel(1) * 100;
    13.                         GUI.Box(new Rect(playButton),
    14.                             "Loading.." + percentLoaded.ToString("f0") + "% Loaded");
    15.             }
    16.         }
    17.        
    18.         if(GUI.Button(Rect(instructionsButton), "Instructions")){
    19.             audio.PlayOneShot(beep);
    20.             menuPage = "instructions";
    21.         }
    22.        
    23.         if(Application.platform != RuntimePlatform.OSXPlayer
    24.              Application.platform != RuntimePlatform.WindowsWebPlayer){
    25.             if(GUI.Button(Rect(quitButton), "Quit")){
    26.                 ButtonAction("Quit");
    27.             }
    28.         }
    29.    
    30.     }else if(menuPage == "instructions"){
    31.         GUI.Label(Rect(instructions), "You awake on a mysterious island... find a way to signal for help or face certain doom!");
    32.                 if(GUI.Button(Rect(quitButton), "Back")){
    33.                     audio.PlayOneShot(beep);
    34.                         menuPage = "main";
    35.                 }
    36.         }
    37.     GUI.EndGroup();
    38.  
    39. }
    I have uploaded an image (CLICK HERE) to my box account illustrating problem I am experiencing, I cannot upload attachments for some reason. Thanks for any help in advance.

    -Dom
     
    Last edited: May 31, 2012
  24. MMortal

    MMortal

    Joined:
    May 21, 2012
    Posts:
    58
    Thanks for this book! Best one I have got (I prefer c#) and I bought 3 of them all from packetpub. This book is great and I really appreciate the update with the video and updated textures. Great job and let me know when the next book is coming out I will get it for sure!!
     
    Last edited: Jun 4, 2012
  25. rockysam888

    rockysam888

    Joined:
    Jul 28, 2009
    Posts:
    650
    Will WillGoldStone publish another new book ?
     
  26. djbyrne

    djbyrne

    Joined:
    Jun 1, 2012
    Posts:
    16
    hey guys,

    I'm having trouble with the downloadable code source that comes with the book.

    i managed to import it to unity but nothing is labeled, all i can find are the textures/materials. theres no models or audio and a bunch of other stuff is missing. I tried re downloading it 3 times but its always the same.

    has anyone else had problems with the code source?

    All that aside I think the book is awesome!
     
  27. kurt

    kurt

    Joined:
    Jul 5, 2012
    Posts:
    1
  28. Irishsun530

    Irishsun530

    Joined:
    Jun 23, 2012
    Posts:
    13
    Hello.

    Of all the book research I've done I keep getting directed to books you have wrote. I currently own Game Development for iOS with Unity3D by Jeff W. Murray. This book is brilliant for everything iOS but I'd love an overall of everything. I jumped into this on my own and now about 8 months down the road I figure a book would be good. :D My question is everything I see about your book is eBook. Is there a hard copy/eBook option? I love the ability to bring the book with me and highlight and write in the margins (Yes, I am one of those people).

    EDIT I feel I should make that more clear. Is there a book and ebook option. I notice on all the forums I have read it refers to ebook option. I'd like to be able to have the book and also ebook so I can keep up with the online posts. (with out doing a double purchase)

    Much Thanks!
     
    Last edited: Nov 6, 2012
  29. Cataclysm31536

    Cataclysm31536

    Joined:
    Dec 28, 2012
    Posts:
    1
    Hello, I am in chapter 4 and I seem to be getting an error saying "The animation dooropen could not player because it could not be found."

    This error occurs when I hit the door while testing. I will include my source code if necessary.
     
  30. PapaPolski

    PapaPolski

    Joined:
    Apr 22, 2012
    Posts:
    7
    Hey guys,
    First of; fantastic book! I just finished it now and everything has been incredibly easy and fun, good job Will! :)

    I have however run into a problem with the menu.. I think a similar problem was posted above. In the main menu on standalone, you can see the "Loading" on the play button. The button is reddish and has the "100% loaded" written on it, and it won't disappear. This shouldn't be occuring in the standalone version. The button works and you can press Play to launch it, but still..
    Here is my code: (C#)

    using UnityEngine;
    using System.Collections;
    [RequireComponent (typeof (AudioSource))]

    public class MainMenuGUI : MonoBehaviour {

    public AudioClip beep;
    public GUISkin menuSkin;
    public Rect menuArea;
    public Rect playButton;
    public Rect instructionsButton;
    public Rect quitButton;
    Rect menuAreaNormalized;
    string menuPage = "main";
    public Rect instructions;


    void Start() {
    menuAreaNormalized = new Rect(menuArea.x * Screen.width - (menuArea.width * 0.5f), menuArea.y * Screen.height - (menuArea.height * 0.5f), menuArea.width, menuArea.height);

    }

    void OnGUI() {

    GUI.skin = menuSkin;
    GUI.BeginGroup (menuAreaNormalized);


    if(menuPage == "main") {

    if(Application.CanStreamedLevelBeLoaded("Island")){
    if(GUI.Button(new Rect (playButton), "Play")) {

    StartCoroutine("ButtonAction", "Island");

    }else{
    float percentLoaded =
    Application.GetStreamProgressForLevel(1) * 100;
    GUI.Box (new Rect(playButton), "Loading.." + percentLoaded.ToString("f0") + "% Loaded");
    }
    }
    if(GUI.Button(new Rect (instructionsButton), "Instructions")) {
    audio.PlayOneShot(beep);
    menuPage="instructions";
    }

    if(Application.platform != RuntimePlatform.OSXWebPlayer Application.platform != RuntimePlatform.WindowsWebPlayer){
    if(GUI.Button(new Rect (quitButton), "Quit")) {
    StartCoroutine("ButtonAction", "quit");
    }

    }else if(menuPage == "instructions") {
    GUI.Label (new Rect(instructions), "You awake on a mysterious island... Find a way to signal for help or face certain doom!");
    if(GUI.Button (new Rect(quitButton), "Back")) {
    audio.PlayOneShot(beep);
    menuPage="main";
    }
    }
    GUI.EndGroup();
    }
    }

    IEnumerator ButtonAction(string levelName) {
    audio.PlayOneShot (beep);
    yield return new WaitForSeconds(0.35f);

    if(levelName != "quit") {
    Application.LoadLevel (levelName);
    }else{
    Application.Quit ();
    Debug.Log ("HaveQuit");
    }
    }

    }

    Also it would be so extremely helpful to be able to find every code used in this book in its "final" form, just to double check and stuff.. :)
    Thanks in advance guys!
     
    Last edited: Feb 22, 2013
  31. Nubz

    Nubz

    Joined:
    Sep 22, 2012
    Posts:
    553

    If you aren't putting it in a web player you can leave those lines of code out like I did.
    I don't know if that will help or not but it only takes a minute to at least comment it out to test.

    for example
    Code (csharp):
    1. if(Application.CanStreamedLevelBeLoaded("Island")) {
    2. if(GUI.Button(new Rect (playButton), "Play")) {
    can be
    Code (csharp):
    1. if (GUI.Button(new Rect(PlayButton), "Play"))
    And work perfectly fine in a standalone build



    Also if I posted my final code it would just cause more confusion I imagine lol.

    Good luck with the book I really enjoyed it myself.
     
  32. sjaak45

    sjaak45

    Joined:
    Dec 10, 2012
    Posts:
    3
    I have the same problem, the loading button won't change back to the play button if it's at 100 %. I can leave the code out, but I would like to get it working, so I understand what's going wrong.

    PHP:

    if(Application.CanStreamedLevelBeLoaded("Island")){
      if (
    GUI.Button (new Rect(playButton), "Play")){
      
    StartCoroutine ("ButtonAction""Island");
    }else{ 
      
    float percentLoaded Application.GetStreamProgressForLevel(1) * 100;
      
    GUI.Box (new Rect(playButton), "Loading.." percentLoaded.ToString("f0") + "% Loaded");
    }
    Maybe in the new unity there is alternative for the "CanStreamedLevelBeLoaded" ?

    Edit: Or maybe the else is at the wrong location?
     
    Last edited: Mar 5, 2013
  33. sjaak45

    sjaak45

    Joined:
    Dec 10, 2012
    Posts:
    3
    I finally fixed the problem, several things went wrong:

    The code was indeed broken, I used the { and } characters at the wrong location. This is the correct code:

    Code (csharp):
    1.             if(Application.CanStreamedLevelBeLoaded("Island")){
    2.             if(GUI.Button(new Rect (playButton), "Play")){
    3.                 StartCoroutine("ButtonAction", "Island");
    4.                 }
    5.             }
    6.             else{
    7.                 float percentLoaded = Application.GetStreamProgressForLevel(1) * 100;
    8.                 GUI.Box(new Rect(playButton), "Loading..." + percentLoaded.ToString("f0") + "% Loaded");
    9.             }
    Also the web export was not set to be streamed (in the build settings). This meant the whole project was loaded, before the loading bar was shown.

    And finally the loading could only be tested when the project was actually uploaded to a website. Even tough the export was for web, the project was loaded to fast when running from the hard disk.
     
  34. nuizzy

    nuizzy

    Joined:
    Sep 28, 2013
    Posts:
    1
  35. Crax

    Crax

    Joined:
    Apr 11, 2013
    Posts:
    13
    Hi, i' m having this issue.
    On chapter 7 "Instantiation and Rigidbodies", at the "Adding the coconut shy shack", when i create the script for the coconut collision with the target (The code is OK, unity isn't giving me any error), when i shoot a coconut on the target, the target won't animate.
    I checked that the script is attached to the target
    And this is my script

    #pragma strict
    private var beenHit:boolean;
    private var targetRoot:Animation;
    var hitSound:AudioClip;
    var resetSound:AudioClip;
    var resetTime:float=3.0f;


    function Start () {
    targetRoot=transform.parent.transform.parent.animation;
    }

    function Update () {

    }
    function OnCollisionEnter(theObject:Collision){
    if (beenHit==true theObject.gameObject.name=="coconut"){
    StartCoroutine("targetHit");
    }
    }

    function targetHit(){
    audio.PlayOneShot(hitSound);
    targetRoot.Play("down");
    beenHit=true;
    yield new WaitForSeconds(resetTime);
    beenHit=false;
    audio.PlayOneShot(resetSound);
    targetRoot.Play("up");
    }
    @script RequireComponent(AudioSource)



    What is my problem? It seems like the collision si not detected.
     
    Last edited: Dec 17, 2013
  36. littleredcloud

    littleredcloud

    Joined:
    Dec 4, 2013
    Posts:
    2
    Hi,

    So I am working on Chapter 7, the coconut shy game.
    I have created the spawner, that worked fine.
    I just updated the PlayerCollisions script to check if the player is standing on the mat. I expected an error saying no mat given I haven't added that model yet, but instead I got this message.

    Assets/Scripts/PlayerCollisions.js(50,30): BCE0019: 'canThrow' is not a member of 'CoconutThrow'.

    I checked CoconutThrow script, which contains...

    static var canThrow : boolean = false;

    so it seems ok to me.

    My player collision script (relevant part) looks like this...

    function OnControllerColliderHit(hit : ControllerColliderHit){
    if(hit.collider == GameObject.Find("mat").collider){
    CoconutThrow.canThrow=true;
    }else{
    CoconutThrow.canThrow=false;

    Any bright ideas? Thanks in advance.

    Ok, I am leaving this post because the solution is too funny, despite making me look like an idiot.

    I had added the relevant line to the CoconutThrow script...but...I hadn't saved it!! Sigh...(facepalm).
     
  37. littleredcloud

    littleredcloud

    Joined:
    Dec 4, 2013
    Posts:
    2
    Hi again,

    So two "proper" issues with the coconut shy game.

    First, my target seemed to be tilted at about 45 degrees. I un ticked Play Automatically in the animations section, and oddly that fixed it to be vertical.

    Secondly, and more importantly, my target doesn't reset after i have knocked it down (either with animations ticked to Play Automatically or without).

    The code seems relatively straight forward, and I can't spot any errors, but I am no coder, perhaps someone else can see some?

    function OnCollisionEnter(theObject : Collision) {
    if(beenHit ==false theObject.gameObject.name=="coconut"){
    audio.PlayOneShot(hitSound);
    targetRoot.animation.Play("down");
    beenHit=true;
    }
    if(beenHit){
    timer += Time.deltaTime;
    }
    if(timer > 3){
    audio.PlayOneShot(resetSound);
    targetRoot.animation.Play("up");
    beenHit=false;
    timer=0.0;
    }
    }

    EDIT To try to work out what was going on, I put a few prints in there, so there's one at the end of each of the three if statements. It correctly runs through the first two ifs, but doesn't get past the third one. I then moved the print statement to be after the line
    if(timer >3){
    and it doesn't get to the print line...something wrong with the timer line?
     
    Last edited: Dec 21, 2013
  38. allgood

    allgood

    Joined:
    Jan 11, 2014
    Posts:
    1
    hi all,

    I'm working through the book, and am on chapter 7, the Particle Systems.

    I want to add the matchbox and to collect it, although I have added the matchbox inside the outpost, I couldn't collect it. I believe there is something wrong wtih my trigger collider, but "battery collect" which is on the same script file works well.

    My matchbox object has a box collider and is a trigger collider. I have created the MatchGUIprefab as told in the book and edited the PlayerCollisions script as told also. Here is the related part (plus the battery part):

    Code (csharp):
    1. function OnTriggerEnter (collisionInfo : Collider)  {
    2.    
    3.     if(collisionInfo.gameObject.name == "matchbox"){
    4.         Destroy(collisionInfo.gameObject);
    5.         haveMatches=true;
    6.         audio.PlayOneShot(batteryCollect);
    7.         var matchGUIobj = Instantiate(matchGUI, Vector3(0.15,0.1,0), transform.rotation);
    8.         matchGUIobj.name = "matchGUI";
    9.     }
    10.    
    11.     if (collisionInfo.gameObject.tag == "battery")  {
    12.         BatteryCollect.charge ++;
    13.         audio.PlayOneShot(batteryCollect);
    14.         Destroy(collisionInfo.gameObject);
    15.     }
    16.  
    17. }
    Any ideas about why it might not working? I would appreciate any help.

    Thanks,
    E.

    EDIT: re-created matchbox and matchboxGUI prefab again and problem solved. I dunno what I did different from the previous one, but now it seems to working just fine.
     
    Last edited: Feb 18, 2014
  39. lorainiscool

    lorainiscool

    Joined:
    Feb 24, 2014
    Posts:
    1
    Hi, i am having the same issue.... did u find any solution to this? We did this in class today and it is working for everyone except myself and another student; no animation or sound
     
  40. fastattacksub

    fastattacksub

    Joined:
    Feb 23, 2014
    Posts:
    13
    I have completely gone through this book and I was able to work through some of the programming glitches. It is a great learning tool and I used as a tool to work more on terrain development. I took this approach and added in mazes with challenges to get through the mazes which makes some interesting game play.
     
  41. fastattacksub

    fastattacksub

    Joined:
    Feb 23, 2014
    Posts:
    13
    I handled the match pickup differently.

    There is a script for matches:

    function OnTriggerEnter(col:Collider){
    if(col.gameObject.tag == "Player")
    {
    col.gameObject.SendMessage("MatchPickup");
    Destroy(gameObject);
    }
    }

    and then in the inventory script:

    function MatchPickup(){
    haveMatches = true;
    AudioSource.PlayClipAtPoint(collectSound, transform.position);
    var matchHUD:GUITexture = Instantiate(matchGUIprefab, Vector3(0.15, 0.1,0), transform.rotation);
    matchGUI = matchHUD;
    }

    I hope this helps with the matches issue.
     
  42. fastattacksub

    fastattacksub

    Joined:
    Feb 23, 2014
    Posts:
    13
    For the door try ray trace as follows
    Player collison script:

    function Update () {
    var hit:RaycastHit;
    if(Physics.Raycast(transform.position, transform.forward, hit, 3))
    {
    if(hit.collider.gameObject.tag=="playerDoor")
    {
    currentDoor=hit.collider.gameObject;
    currentDoor.SendMessage("DoorCheck");
    }
    }
    }

    Door Check script
    function Start () {
    doorTimer=0.0f;
    }

    function Update () {
    if(doorIsOpen)
    {
    doorTimer +=Time.deltaTime;
    if(doorTimer>doorOpenTime)
    {
    Door(doorShutSound, false, "doorshut");
    doorTimer=0.0f;
    }
    }
    }

    function DoorCheck(){
    if(!doorIsOpen)
    {
    Door(doorOpenSound, true, "dooropen");
    }
    }

    function Door(aClip:AudioClip, openCheck:boolean, animName:String){
    audio.PlayOneShot(aClip);
    doorIsOpen=openCheck;
    transform.parent.gameObject.animation.Play(animName);
    }
     
  43. fastattacksub

    fastattacksub

    Joined:
    Feb 23, 2014
    Posts:
    13
    Coconut thrower script


    function Update () {

    if(Input.GetButtonDown("Fire1")&canThrow)
    {
    audio.PlayOneShot(throwSound);
    var newCoconut:Rigidbody=Instantiate(coconutPrefab, transform.position, transform.rotation);
    newCoconut.name="coconut";
    newCoconut.velocity = transform.forward*throwSpeed;
    Physics.IgnoreCollision(transform.root.collider, newCoconut.collider, true);
    }
    }

    @script RequireComponent(AudioSource)


    targetcollison script

    function Start () {
    targetRoot = transform.parent.transform.parent.animation;
    }

    function Update () {

    }

    function OnCollisionEnter(theObject:Collision){
    if(beenHit==false&theObject.gameObject.name=="coconut")
    {
    StartCoroutine("targetHit");
    }
    }

    function targetHit(){
    audio.PlayOneShot(hitSound);
    targetRoot.Play("down");
    beenHit=true;
    CoconutWin.targets++;

    yield new WaitForSeconds(resetTime);

    audio.PlayOneShot(resetSound);
    targetRoot.Play("up");
    beenHit=false;
    CoconutWin.targets--;
    }

    @script RequireComponent(AudioSource)
     
  44. parikshit6321

    parikshit6321

    Joined:
    Mar 1, 2014
    Posts:
    1
    Hey guys i can't find the assets that are supposed to be provided with this book. I am reading the e-book version. When i go to the mentioned link, it says "Unfortunately, the page you were trying to retrieve does not exist!". Can anyone of you help me with the assets. I can't proceed without them.
     
  45. OboShape

    OboShape

    Joined:
    Feb 17, 2014
    Posts:
    836
    Hi,

    since you have bought the book, you can go to the publishers site PackT Publishing and go to the support section and download all the sample code and support files from there. there may be alot of the assets available in Unity's asset store possibly.

    Support Link to publishers site

    hope you find what you are looking for,

    ObO
     
    Last edited: Mar 5, 2014
  46. eric848

    eric848

    Joined:
    Nov 9, 2014
    Posts:
    4
    When i write the script for the door, unity says that I have a lot of mistakes, and I dont understand anything,

    Can someone post the script for the door please?
     
  47. willgoldstone

    willgoldstone

    Unity Technologies

    Joined:
    Oct 2, 2006
    Posts:
    794
    What are the errors with the door? it's much better to learn if you just try and figure out what is wrong with the code. There are no mistakes in the code in the book outside of errata listed at http://unitybook.net. So why not screenshot the errors and others can help you here in figuring out what the problem is.

    Will
     
  48. eric848

    eric848

    Joined:
    Nov 9, 2014
    Posts:
    4
    ok i will check the mistakes
     
  49. eric848

    eric848

    Joined:
    Nov 9, 2014
    Posts:
    4
    When i click on "add component" to add my script "player collision" I can't find it in the list
     
    Last edited: Nov 9, 2014
  50. willgoldstone

    willgoldstone

    Unity Technologies

    Joined:
    Oct 2, 2006
    Posts:
    794
    Do you have other errors that mean that script won't compile? if the console shows errors, that would be why you won't be allowed by Unity to add it. Also, is the script named 'PlayerCollision', and does this match with the class name inside the script near the top?