Book Errata

Despite stringent checks in the book, sometimes mistakes go unnoticed. Whilst both Packt’s production team and I apologise for these, we promise to provide a comprehensive detailing of any noted errata here, in page order.

If you spot an error in the book that you believe should be listed here, please use the Contact form to get in touch with us, writing ‘Error’ in the subject line.

Known Errors

Page 169 - Javascript Typo, Lower case “s” in the function name shutDoor.

function shutDoor(door : GameObject){

should read -

function ShutDoor(door : GameObject){

Page 182 – Missing ‘Player’ Tag on First Person Controller Prefab

Due to a mistake in the Prefab provided by Unity Technologies – the First Person Controller prefab that you import at the start of the book does not have the tag ‘Player’ as its counterpart Third Person Controller does. The TriggerZone script relies on this tag being on the First Person Controller prefab (and therefore on the game object in the scene), so simply select it within the Standard Assets > Character Controllers folder of the Project panel, and choose ‘Player‘ from the Tag drop down menu at the top of the Inspector panel.

Page 258 – Javascript variable declaration, spaces mistakenly added by publisher
(Kindle edition page 327)

Lines within the Javascript chunk in the middle of the page, that say -

var hit Sound : AudioClip;
var reset Sound : AudioClip;
var reset Time : AudioClip;

Spaces have been placed into the names, remove them to it reads -

var hitSound : AudioClip;
var resetSound : AudioClip;
var resetTime : AudioClip;

Page 264 / 269 – Javascript code missing a space

@scriptRequireComponent(AudioSource)

should read -

@script RequireComponent(AudioSource)

page 267 – Javascript code missing ‘var’

winCell : GameObject = transform.Find(“powerCell”).gameObject;

should read -

var winCell : GameObject = transform.Find(“powerCell”).gameObject;

(as shown in the complete script on the following page).

Page 300 to 301 – Javascript code error

On this page, we use javascript code to grab both Particle Emitters – the fire and the smoke – and then set their emit value to true.
The book states that you should use this line -

var FireEmitters : ParticleEmitter[];

followed by this for loop to go through the array and set each emitter found to true -

for(var emitter : ParticleEmitter in fireEmitters){
emitter.emit = true;
}

Whilst this approach works in C# it was not sufficiently tested in Javascript. Apologies for this mistake. The reason this does not work is that in Javascript, the GetComponentsInChildren command returns an array of Components instead of specifically ParticleEmitter components, so they must be converted during the array.

Delete the aforementioned code, and place in the following -

var fireEmitterComponents : Component[] =     campfire.GetComponentsInChildren(ParticleEmitter);

var fireEmitter : ParticleEmitter;

for (var i=0; i< fireEmitterComponents.Length; i++) {
fireEmitter = fireEmitterComponents[i] as ParticleEmitter;
fireEmitter.emit=true;
}

Here we begin by establishing an array of type Component[]. We then set this using the equals symbol to Particle Emitters found in the campfire gameobject’s children as before.

We then make a singular variable called FireEmitter, of type ParticleEmitter. This is then used in the for loop to represent the current emitter being modified. We then make a for loop that begins by creating a variable called ‘i’, set to 0. This variable represents the particular entry in the array, so wherever you see ‘i’ mentioned, this means the current entry in the array that is being addressed. The loop runs for as many entries as there are in the fireEmitterComponents array – hence the use of ‘.Length’.

For each entry in the array, we use our temporary fireEmitter variable created above the for loop, and set it equal to the current entry in the fireEmitterComponents array, setting its type to ParticleEmitter by using ‘as ParticleEmitter’. We then set this emitter’s emit value to true as done originally in the book.

Page 327 – Javascript variable declaration

The second line -

var GUISkin : GUISkin;

Should read -

var menuSkin : GUISkin;

Page 354 – Javascript code typo

var winObject : GameObject;

should read -

var winObj : GameObject;

80 thoughts on “Book Errata

  1. Question for you, on page 158 when you explain the first method to make the outpost door open, i always get an error when i type:

    Collision detectionOnControllerColliderHit, working withfloat doorTimer = 0.0f;

    all the other variables work, it’s just that one that gives me a hard time. What gives?

    • How do you mean ‘when I type ‘Collision detectionOnControllerColliderHit’ – you aren’t typing literally that right?

      • Yea I actually was typing that literally. The book showed the variables listed as such:
        bool doorIsOpen = false;
        Collision detectionOnControllerColliderHit, working with float doorTimer = 0.0f;
        What part of that am I not suppose to write?

  2. I have it for my mom’s kindle so I wouldn’t know how to send you a pic, its all good though. I’m picking everything up now, if something else goes wrong I’ll come bug you a little more.

  3. On page 169 in both the C# and Javascript you published this line referring to an animation to close the door.

    door.transform.parent.animation.Play(“doorshut”);

    In the downloaded Book assets the animation to shut the door is actually named “doorclose”.

    • Sorry for the confusion Andrew – the book assets should feature the outPost with no animations attached however – are you saying they were filled in on the import settings when you opened?

      • My bad, I’m the culprit here. I think I need myself proofread. I checked the process I went through and I made the error. Ugh!. Sorry about that. Oh, and if you hear a noise.. its just me banging my head against my desk. :)

        Great book by the way.

  4. I have a problem on page 268.. I have wrote the script for the coconutWin and applied it to the coconut shy parent as stated in the book. However when I go to run the game I only get the sound effect of the winCell. I have an error on my script that says “NullReferenceException
    CoconutWin.Update () (at Assets/Standard Assets/Scripts/CoconutWin.cs:23)”
    I have tried re-writing the script but it still come up with the error message. I am using the C# language and my script is identicle to the script in the book. Can you please help me with this issue.

    Here is a picture of my script: http://tinypic.com/r/8xlpb7/5

    abd heres a visual representation of the error message: http://i44.tinypic.com/i237v4.png

    thanks in advance

    • Strange – looks like it cannot find ‘powerCell’ in your scene, as its erroring on line 23. Have you renamed that object? it should be able to find it, its a child of your coconutShy shack. Can you check that or send a picture of your Hierarchy with that object expanded please?

      • When the powerCell is a chil of the coconut shy the powerCell comes out but I can’t interact with the object even when I put a collider on it and use the powerxell script on the object I still cant pick it up. Does the powercel need to be a child of the child cocnut shy?

        Here is a screenshot of the code and my hierarchy

        Code: http://i44.tinypic.com/653k29.png

        Error: http://i41.tinypic.com/fl8s5s.png

        Hierarchy: http://i44.tinypic.com/3354kt5.png

        Prefab screenshot: http://i41.tinypic.com/10ginhl.png

        The markers around the last screen shot it to notate which prefab I have put on the script.

        • Have you assigned your cellPrefab in the Inspector? that’s all I could guess would be missing – the code is correct. Also, yes powerCell should be a child – its part of the original model so don’t alter it, let the script do the moving and deleting it is supposed to. We are basically pulling that child object out, deleting it and replacing it with our prefab powerCell – that we know we can pickup. Also your powerCell 1,2,3 objects are in red in the Hierarchy as if they have lost their link to the original asset – can you still pick them up alright?

          • Yes I can still pick them up ok. What i did was delete the original prefab from the folder and added the one from the model. I though they would conflict and the script would get confused so i re-named them powerCell 1,2,3.

        • You might have done the same thing I did… I accidentally dragged the PowerCell from the Models folder and not from the PreFab folder (it needs to come from the PreFab folder) and as the other fellow said, the script needs to be on the topmost parent of the CoconutShy (and not any of the children).

    • Yes, you cannot delete the prefab – you are supposed to be instantiating it (creating a new instance of it) when you delete the fake one on the inside of the coconutShy. What have you got assigned to that public variable? surely if you have deleted the prefab, that variable is blank?

  5. I got the script to work by turning off the animation and applying the script to the main cocnutshy instead of the parent cocnut shy.. but i am still getting the NullReferenceException error.

  6. Here’s one for you … I just finished chapter 6 and my charge variable is incrementing for no reason. In other words my character randomly collects all the batteries without intersecting the colliders. There is no consistency as to when it happens. Not in the same spot. Sometimes when it’s happened and I stop moving, the incrementation stops, only to finish when I move again. The program works perfectly 50% of the time. I’ve checked and rechecked the classes. Any ideas? Thanks for an excellent guide by the way!

    • Rodney – I can only assume that you’re incrementing not inside the ‘if’ statement of your collision detection function, as such whenever you collide with Anything you will get an increment. Make sure you only increment IF the object collided with is the powerCell – hope that makes sense!

  7. I have a problem on page 163 .. I have wrote the script for the PlayerCollisions as stated in the book. However when I run the game there are no sound effect at the door Outpost door. scripts as below. Can you please help me with this issue.

    using UnityEngine;
    using System.Collections;

    public class PlayerCollisions : MonoBehaviour {
    bool doorIsOpen = false;
    float doorTimer = 0.0f;
    public float doorOpenTime = 3.0f;
    public AudioClip doorOpenSound;
    public AudioClip doorShutSound;

    // Use this for initialization
    void Start () {
    }

    // Update is called once per frame
    void Update () {

    }

    void OnControllerColliderHit(ControllerColliderHit hit) {
    if(hit.gameObject.tag == “playerDoor” && doorIsOpen == false) {
    OpenDoor(hit.gameObject);
    }
    }

    void OpenDoor(GameObject door) {
    doorIsOpen = true;
    door.audio.PlayOneShot(doorOpenSound);
    }
    }

      • Hi there,

        Chapter 5 Audio —
        This audio is not working for me :(. I have followed the instructions step by step or JavaScript and I keep getting a NullReferenceException (UnityEngine.GameObject door) at (Assets/ Scripts/PlayerCollisionjs.js). It seems that a chunk of the book is missing at page 148. So this is saying it cant find the object. I do see it loaded in the Inspector script attached to the First Person Controller Door Open Sound – door_open and Door Shut Sound – door_shut

        If you were able to get it working, please do let me know what was missing. Best,
        Robin

  8. Just wanted to let you know that the link for the Glossary download excerpted from pages 3 and x in the book below seems to be broken.

    The Glossary is not present in the book but is available as a free download
    from the following link:
    http://www.packtpub.com/sites/default/files/
    downloads/1444OT_Glossary_Final.pdf

    Thanks again for a great book which I just picked up and am enjoying it immensely where I also appreciate this question forum as I am sure to have some questions as I move through the book as I am new to Unity 3D.

    • Hi John, I’ll get the link fixed, thanks for raising it! I’ve also put it up for download on this site – see Downloads page – to make things easier!

  9. Hello,

    This isn’t exactly a mistake; it is just in need of an update. In chapter eight you explain particle systems by way of the fire, smoke and accompanying scripting. Of course, your explanation is of the old ellipsoid particle system rather than the new Shuriken particle system.

    I am aware that I can simply use the legacy particle system. I am also aware that Shuriken offers a better finished product than the older system. For that reason, I would rather learn the updated system. Is there an update for chapter eight in the works? Thanks.

    • As I replied to your other comment – see the Updates section, complete guide for using Shuriken and completing Chapter 8 there, have fun!

  10. Wow, I am finding chapter eight to be unnecessarily frustrating. I cannot get the Shuriken particle system to respond to the Javascript array you suggest in the list of corrections above. I found this answer on the Unity forum, which suggests that you cannot change via scripting any of the variables in the Shuriken particle system. If this is true, I don’t see how I can complete the tutorial game using Shuriken.

    I would appreciate a response at your earliest convenience. Thank you.

  11. Chapter 4 > Return type

    Javascript

    private var currentAmount : float;
    function DoSums() : float
    {
    var amount : float = 5.0 + 55.8;
    return amount;
    }

    The JavaScript Equivalent of the following C# code is missing

    C#
    void Update()
    {
    if(Input.GetButtonUp(“Jump”))
    {
    currentAmount = DoSums();
    }
    }

    Shall I simply learn both JavaScript and C# for Unity? It seems you go back and forth allot. I seem to remember reading something about “Pick a language”.

    • First off, you needn’t post this 3 times. Yes the Update function is missing – but the only difference is that it has the word ‘function’ instead of void, otherwise it’s the same as the c#. Also you Should pick a language- as explained in this chapter the FPS example script is shown in js as the examples translate – you simply need to understand the concepts. The rest of the book shows every single code snippet in both languages.

      • Okay. One more note of consequence. The Kobo version of this book seems to have some OCR errors going on, as mentioned in one of my error reports. The reason for posting that error (twice) and then the next one after it, is because I forgot to use “Error” as my subject line, so I thought I should repost or I my feedback might go un-noticed. I took out a monthly subscription to packt lib and low and behold many of the OCR errors are simply not there. I don’t think I’ll trust KOBO for a while on technical material, but thanks for the great book!

  12. Erorr

    Chapter 4 > Return type

    Javascript

    private var currentAmount : float;
    function DoSums() : float
    {
    var amount : float = 5.0 + 55.8;
    return amount;
    }

    The JavaScript Equivalent of the following C# code is missing

    C#
    void Update()
    {
    if(Input.GetButtonUp(“Jump”))
    {
    currentAmount = DoSums();
    }
    }

    Shall I simply learn both JavaScript and C# for Unity? It seems you go back and forth allot. I seem to remember reading something about “Pick a language”.

  13. Error

    Chapter 4
    Calling a custom function
    Javascript

    Line (custom function, callingJavaScriptvar spawn1 : Transform;)
    should be (var spawn1 : Transform;)

  14. on page 215 where it says to add

    if (GameObject.Find(“PowerGUI”)){
    Destroy(GameObject.Find(“PowerGUI”));
    doorLight.color = Color.green;

    I added it, and the other codes on the following pages until I am advised to test the game to see the text about the door being locked and needs power. Neither the text, no charge gui or the the door locked sound occurs. It is only until I collect all 4 power cells and enter the outpost, the text and the locked door sound works with the error message:

    MissingReferenceException: The object of type ‘GUITexture’ has been destroyed but you are still trying to access it.
    Your script should either check if it is null or you should not destroy the object.

    But if I comment out the code I mentioned above everything works just as it is supposed to with the Hint text appearing.

    Please help. I have been stuck on this problem for the whole day now and cannot figure it out.

    • Hi There, this error doesn’t make sense as it is checking for the PowerGUI so even if it has been destroyed you aren’t trying to access it- it will simply not find it any longer- are you sure the error refers to this line?

      • It definitely has something to do with that code. I place the if statement under the line

        transform.FindChild(“door”).SendMessage(“DoorCheck”);

        but nothing happens when I approach the door without any power. Here is my full triggerzone script:-

        using UnityEngine;
        using System.Collections;

        public class TriggerZone : MonoBehaviour {

        public Light doorLight;

        // Use this for initialization
        void Start () {

        }

        // Update is called once per frame
        void Update () {

        }
        public AudioClip lockedSound;
        public GUIText textHints;

        void OnTriggerEnter(Collider col){
        if(col.gameObject.tag == “Player”){
        if (Inventory.charge == 4){
        transform.FindChild(“door”).SendMessage(“DoorCheck”);
        if (GameObject.Find(“PowerGUI”)){
        Destroy(GameObject.Find(“PowerGUI”));
        doorLight.color = Color.green;
        }
        else
        {transform.FindChild(“door”).audio.PlayOneShot(lockedSound);
        col.gameObject.SendMessage(“HUDon”);
        textHints.SendMessage(“ShowHint”, “This door seems locked.. maybe that generator needs power…”);
        }
        }
        }
        }
        }

        • Hin,

          It looks like your else statement is nested in the wrong if statement. It really helps to see this if you have proper indentations in your code so you can see where all your closing braces are. The else statement is supposed to be for this if statement:

          if(col.gameObject.tag == “Player”)

          Instead, you accidentally have it for:

          if (GameObject.Find(“PowerGUI”))

          Try placing a closing brace right before the else statement. Also remove one of them at the end of the code block.

          Hope that helps.

  15. found the error…simple typo….OnControllerColliderhit should be OnControllerColliderHit……. read the script dozens of times w/o noticing that one small error….sorry to fill up your errata forum w/ my newb-ness

  16. I have a small problem with Chapter 6, page 209. I have the Inventory script which holds the HUDon() method attached to my FirstPersonController. In the TriggerZone script, I have the line: -

    col.gameObject.SendMessage(“HUDon”);

    …in the OnTriggerEnter(Collider col) method. The AudioClip for the locked sound is assigned to the public variable lockedSound which shows up in the Inspector panel when the outPost parent object is selected in the Hierarchy. The first problem is that the lockedSound plays as soon as I press play in Unity to test it. Which is weird. The second more serious issue is that I get the error “SendMessage HUDon has no receiver!” which points to the line above. However, the method still works as designed and the GUITexture is enabled.

    ClearOnPlay is enabled in the debugger, so it’s not an old error.

    Any ideas? Love your book, BTW. Best Unity book I’ve bought.

    • Firstly, uncheck ‘Play on Awake’ in the audio source to stop it playing a sound immediately. Secondly if you you’re seeing ‘has no receiver’ then there is no function that exists on the object you’re sending a message to. So you need to ensure its correctly spelt and that the script IS indeed attached to the object you refer to. Hope that helps :)

      • I just had this problem too. Both the TriggerZone and Inventory scripts were properly placed on their respective gameobjects, and the functions were spelled correctly. I eventually had TriggerZone print the name of the collider it was colliding with and I found the answer.

        The issue was that as soon as I entered play mode, the trigger collider registered the outpost’s door as a collision. Since the DoorManager script doesn’t have a HUDon function, Unity complained that SendMessage doesn’t have a receiver. My solution was simple – I nested the SendMessage line in another if(col.gameObject.tag == “Player”) and now everything works as expected.

        What did I miss that would cause this? Was there a step in the book that would have prevented the door collider from triggering the box collider?

  17. unction LightFire(campfire : GameObject){
    var fireEmitterComponents:Component[]= campfire.GetComponentInChildren(Emission);

    var fireEmitter : ParticleEmitter;

    for(var i=0; i Emission is the ‘path’
    Thank you Will!

  18. On page 143, when setting up the outpost model it says to set the Material-Generation to Per Texture. I cannot find this in the FBXImporter component. I’m using Unity 3.5.6f4

    • 99% sure its there in 3.5.6, it changes in 4.x, see updates page. How come you aren’t using 4.x btw? Assuming you’re a license holder then?

  19. You cant play the game twice in a row. The second time the powercell from the game is not released. Here is why.
    In CoconutWin we declare two static vars

    public static int targets = 0;
    public static bool haveWon = false;

    When you play the game and exit the trigger these vars will get -3 and True. targets will get -3 because as soon as we know dome all three targets the target var is set to 0, but the target models get up after a specific amount of time and substract — from the variable target. So the var gets to -3.

    When you finish tha game and press play again on the menu these varaibles are never reset back to 0 and false. To fix this place

    CoconutWin.targets = 0;
    CoconutWin.haveWon = false;

    in GameOver() of gameOver.cs

  20. I’m having a problem with the PlayerCollisions.js file. When I try to add it to the FirstPersonController I get a “Can’t add script” error.

    “The scripts file name does not match the name of the class defined in the script!”

    I’m using Unity 4.x

    • Then you should ensure that they do match! However this should happen with js as the class declaration is built in- which makes me worry you are writing c# into a js file? Maybe paste me a pastebin.com link so i can take a look at what you have written ?

  21. Hi,

    Using book for Unity 4, no problem up to p256, except animation interfaces bit different. On 256 became problem because my Inspector showed ‘Animator’ component instead of ‘Animation’ component. However I found switching to to ‘legacy’ under ‘animation type’ fixed issue. Hope this helps. Sorry if you covered this elsewhere and I missed it.

    • Thanks Peter, always appreciate contributions like this – I’ve now covered some of it in the Updates page.

  22. Hi Dont know if i’ve missed a step in Chapter 6, but i’ve just finished creating the Inventory script, but when testing it. i walk into the powercells and nothing happens they stay in the environment slowly spinning, i hear no sound and object stays.

    Inventory.cs
    using UnityEngine;
    using System.Collections;

    public class Inventory : MonoBehaviour {
    public static int charge = 0;
    public AudioClip collectSound;

    // Use this for initialization
    void Start () {
    charge = 0;
    }

    //CellPickup Function
    void CellPickup () {
    AudioSource.PlayClipAtPoint (collectSound, transform.position);
    charge ++;
    }

    // Update is called once per frame
    void Update () {

    }
    }

    PowerCell.cs
    public class PowerCell : MonoBehaviour {
    public float rotationSpeed = 100.0f;

    // Use this for initialization
    void Start () {

    }

    // Update is called once per frame
    void Update () {
    transform.Rotate (new Vector3 (0,rotationSpeed * Time.deltaTime ,0));
    }

    //Trigger Collision Detection
    void OnTriggerEnter (Collider col) {
    if(col.gameObject.tag == “Player”){
    col.gameObject.SendMessage (“CellPickup”);
    Destroy(gameObject);
    }
    }
    }

    Are the scripts correct?

      • No thats tagged up as player. just found the problem, Capsule collider wasn’t set to “Is Trigger”. thanks for coming back anyway

  23. Greetings, May1st, 2013, 5 pm KTM,Nepal
    Target’s animation (idle, down & up) is not working.
    1. there is not error on code.
    2.target is parented under coconutShy.
    3.target, target_support1 & target support2 have rigid body component
    check Is kinematic & uncheck Gravity.
    4. animation (idle, down & up)
    5.play automatically is unchecked.
    code:
    private var beenHit : boolean = false;
    private var targetRoot : Animation;
    var hitSound : AudioClip;
    var resetSound : AudioClip;
    var resetTime : float = 3.0;

    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;
    yield new WaitForSeconds(resetTime);
    audio.PlayOneShot(resetSound);
    targetRoot.Play(“up”);
    beenHit=false;
    }
    @script RequireComponent(AudioSource)

  24. Will,
    I’ve made it to page 169 of the Kindle version of your book before I stumbled. For some reason, after rewriting the code in the Code Maintainability section the door no longer opens or closes. I just get the sounds. I’ve reread the section several times–even started from the beginning–and still can’t make it work. Can you please point out what I’ve done wrong?
    A great book, by the way.
    Thanks,
    Oli

    using UnityEngine;
    using System.Collections;

    public class PlayerCollisions : MonoBehaviour {
    bool doorIsOpen = false;
    float doorTimer = 0.0f;
    public float doorOpenTime = 3.0f;
    public AudioClip doorOpenSound;
    public AudioClip doorShutSound;
    GameObject currentDoor;

    // Use this for initialization
    void Start () {

    }

    void Update () {
    if(doorIsOpen){
    doorTimer += Time.deltaTime;
    if(doorTimer > doorOpenTime) {
    Door (doorShutSound, false, “doorshut”, currentDoor);
    doorTimer = 0.0f;
    }
    }
    }
    void OnControllerColliderHit(ControllerColliderHit hit){
    if(hit.gameObject.tag == “playerDoor” && doorIsOpen == false) {
    currentDoor = hit.gameObject;
    Door(doorOpenSound, true, “dooropen”, currentDoor);
    }
    }

    void Door(AudioClip aClip, bool openCheck, string animName, GameObject thisDoor){
    thisDoor.audio.PlayOneShot(aClip);
    doorIsOpen = openCheck;
    thisDoor.transform.parent.animation.Play(“animName”);
    }
    }

    • So the error there is telling you what the issue is, it just takes a little understanding to decipher it. So let’s look at it -

      “The animation state animName could not be played because it couldn’t be found!”

      This is saying that you are asking it to play an animation clip literally called ‘animName’ – however, it should never say that, because it should be taking whatever animation is in a variable called animName – and then the error should say the name of whatever clip you’re asking it to play (but only if it coulnd’t be found).

      So what are you doing wrong? well quite simply, as we are using the variable animName to represent a string of data – “anything in inverted commas like this” – then it is already a string, so does not need the inverted commas – so in your last line of code you have this -

      thisDoor.transform.parent.animation.Play(“animName”);

      but you should have this -

      thisDoor.transform.parent.animation.Play(animName);

      Otherwise you’re telling Unity to try and literally play an animation called “animName”, which indeed, cannot be found.

  25. lot of problems using book with unity 4.1.5, chapter 3 creating environment, first person controller keeps falling through the terrain.I have been stocked there for 3 weeks now

    • Actually Stan that’s incorrect, the book works fine with 4.1.5 – if you are stocked (stuck?) then don’t wait 3 weeks to comment just ask! If your character is falling through then they aren’t set up correctly.. Have you retraced your steps? There aren’t really any to retrace as its just dragging in the first person controller- i am guessing but all I can think is that you must have left the collider intersecting with the terrain? If I’m wrong please reply with a screenshot of your character setup in unity with the fps controller selected in hierarchy and I’ll have a rethink! Good luck

  26. page 169
    I get null Reference exception, from call this function door.transform.parent.animation.Play(“dooropen”); dooropen is animation clip created on the animation part of the outPost

  27. Pls I need your help on this particle emitter ,is it the same as Ellipsoid particle emitter because after I added it to the FireSystem and followed the instruction on the book I got different result, my fire color is pink and when I unchecked emitter for the fire and smoke they don’t work

  28. Hi I’ve just completed the youtube video section on particle system, added the matches and updated the script in at per page 303, assigned TextHintGUI to the text hints variable on the First Person Controller. but something appears to be wrong.

    I’m not getting the hint or lighting the fire. I’ve re-read the section several times but can’t see the problem. could you point me in the right direct please. Inventory script below

    public class Inventory : MonoBehaviour {
    public static int charge = 0;
    public AudioClip collectSound;
    // HUD
    public Texture2D[] hudCharge;
    public GUITexture chargeHudGUI;
    //Generator
    public Texture2D[] meterCharge;
    public Renderer meter;
    //Matches
    bool haveMatches = false;
    public GUITexture matchGUIprefab;
    GUITexture matchGUI;
    public GUIText textHints;

    // Use this for initialization
    void Start () {
    charge = 0;
    }

    //CellPickup Function
    void CellPickup () {
    AudioSource.PlayClipAtPoint (collectSound, transform.position);
    charge ++;
    chargeHudGUI.texture = hudCharge[charge];
    meter.material.mainTexture = meterCharge[charge];
    HUDon ();
    }
    void HUDon () {
    if (!chargeHudGUI.enabled){
    chargeHudGUI.enabled = true;
    }
    }

    // MatchPickUp function
    void MatchPickup (){
    haveMatches = true;
    AudioSource.PlayClipAtPoint (collectSound, transform.position);
    GUITexture matchHUD = Instantiate (matchGUIprefab, new Vector3(0.15f, 0.1f, 0), transform.rotation) as GUITexture;
    matchGUI = matchHUD;
    }

    //Starting Fire
    void OnControllerColliderHit (ControllerColliderHit col){
    if (col.gameObject.name == “Campfire”){
    if (haveMatches){
    LightFire(col.gameObject);
    }else{
    textHints.SendMessage (“ShowHint”,
    “I could use this campfire to signal for help..” +
    “If only I could light it..”);
    }
    }
    }

    //Lighting Fire
    void LightFire(GameObject campfire){
    campfire.GetComponentInChildren().Play();

    campfire.audio.Play();
    Destroy(matchGUI);
    haveMatches=false;
    }

  29. Hi, I am on Chap 5 of the book and trying to create a trigger zone but the door will not open. When I used the first approach (collider collision), the door opens and shuts with no problem. The message that I get is “SendMessage DoorCheck has no receiver!”.

    using UnityEngine;
    using System.Collections;

    public class TriggerZone : MonoBehaviour {

    // Use this for initialization
    void Start () {

    }

    // Update is called once per frame
    void Update () {

    }

    void OnTriggerEnter(Collider col){
    if(col.gameObject.tag == “Player”){
    transform.FindChild(“door”).SendMessage(“DoorCheck”);
    }

    }

    }

  30. I’ve updated the previous code but the door still does not open. I have extended the boundary dots for the box collider for outPost already.

    using UnityEngine;
    using System.Collections;

    public class TriggerZone : MonoBehaviour {

    bool doorIsOpen = false;
    float doorTimer = 0.0f;
    public float doorOpenTime = 3.0f;
    public AudioClip doorOpenSound;
    public AudioClip doorShutSound;

    // Use this for initialization
    void Start () {
    doorTimer = 0.0f;
    }

    // Update is called once per frame
    void Update () {
    if(doorIsOpen){
    doorTimer += Time.deltaTime;
    if(doorTimer > doorOpenTime){
    Door(doorShutSound, false, “doorshut”);
    doorTimer = 0.0f;
    }
    }

    }

    void DoorCheck(){
    if(!doorIsOpen){
    Door(doorOpenSound, true, “dooropen”);
    }
    }

    void Door(AudioClip aClip, bool openCheck, string animName){
    audio.PlayOneShot(aClip);
    doorIsOpen = openCheck;
    transform.parent.gameObject.animation.Play(animName);
    }

    void OnTriggerEnter(Collider col){
    if(col.gameObject.tag == “Player”){
    transform.FindChild(“door”).SendMessage(“DoorCheck”);
    }

    }

    }

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>