Problem Going Through "Unity Game Development Essentials" by Will Goldstone

Hi, I am currently using the latest version of basic Unit (3.something)

and this book is a little outdated however most of the things are the same. But for me, the problem arises not when the things differ, but on section that should be really easy.

Starting on page 111, where the book introduces you to basic collision detection.

So in their exercise I am modifying a door that detects my avatar (capsule) and animates and opens.
I have done what they have listed Created the new script >> Programmed the script as described in the book >> Saved >> Dragged the script into the FPS Controller. That however still left me locked out, the door apparently doesn’t detect me and doesn’t open.

I have decided to move on after numerous attempts to RayCasting, which worked for some reason (by commenting out the Collision in the same script)

Now I think the problem has also compounded because later it asks to collect the batteries, using Trigger, which again, I cannot do.

Is there any advice / help that anyone has on their minds?

Thanks in advance.

:wink:

Hi a few questions I’d ask right away - are you using OnCollisionEnter or OnTriggerEnter - both parts are covered in the book so I wondered which part you’re working on? Could you post your code to pasteit4me.com and pics of your setup to tinypic.com and i’ll try and help!

Currently updating the book with new stuff and fixing any problems that may arise from the new version but mostly you should be fine using it with Unity 3.0 as it stands.

Wow thanks for the reply! I found out that I could solve half of the problems by deleting objects and starting over the code for them. Yes I used both, CollisionEnter gives a model a physical property (aka can’t walk through it) whereas Trigger makes it walkthroughable ( for collision detection which then makes it disappear).

I am currently on the later part of the of the tutorial where I am getting the matchBox to light up the fire however, when getting the matchbox, that last line of code the one that has to do with matchGUI and matchGUIobj, it gives me an error that it cannot be found. And then when i light the fire, i assume the error follows through and the GUItexture of matches is not destroyed. I am currently trying to figure that out.

Just out of curiousity, for scripting parts, do you plan on writing out the entire source code as oppose to fragmented code?

Thanks !

No you should be able to go through it a bit at a time. For errors double check what you’re experiencing isn’t part of the errata listed at packtpub.com’s support section. Also check your code against the full script in the code download.

Hi thanks for your reply, i have checked the errata section, they did mention the page 201 where you need to add the matchGUIprefab into the FPS controller, but I did that, and my error is something else.

I have a screenshot:

URL (ImageShack - Best place for all of your image hosting and image sharing needs)

last line in the script matchGUIobj.name = matchGUI;

the error pointed to that when i double clicked that. I assume this has something to do with destroying the GUI sprite after I light the fire… which of course I tried to do and it doesn’t disappear. (note this was a quick project version, i have done everything until this point but it’s on the work computer, but I get the same error there)

This was my 2nd attempt at redoing this step, and I am wondering if I am missing anything.

:slight_smile: Thanks a lot.

Hey T_Trojan

Did you have any luck with your problem and if so can you share it with me I’m having problems as well in chapter 7.

Thanks

i need help in Ch 4 with making the door open and close. This is my code but i hate coding and am not very good at it so anyhelp would be great.

private var doorIsOpen : boolean = false;
private var doorTimer : float = 0.0;
private var currentDoor : GameObject;

var doorOpenTime : float = 3.0;
var doorOpenSound : AudioClip;
var doorShutSound : AudioClip;

function Update () {
if(doorIsOpen){
doorTimer += Time.deltaTime;

if(doorTimer > 3){
Door(doorShutSound, false, “doorshut”, currentDoor);
doorTimer = 0.0;
}
}
}

function OnControllerColliderHit (hit : ControllerColliderHit){
if (hit.gameObject.tag == “outpostdoor” doorIsOpen == false){
currentDoor = hit.gameObject;
Door(doorOpenSound, true, “dooropen”, currentDoor);
}
}

function Door(aClip : AudioClip, openCheck : boolean, animeName : String, thisDoor : GameObject){
audio.PlayOneShot(aClip);
doorIsOpen = openCheck;

thisDoor.transform.parent.animation.Play(animeName);
}

@script RequireComponent (AudioSource)