Need help with a simple problem.

Hey guys. My name is Tyler. I am in the tenth grade, and I have recently downloaded the Unity 3D Indie demo as a means to further feed my creative side. However, this is all very, VERY new to me.

I am a musician. I write original music, play in a band, etc. I had never really heard of Unity 3D until recently, a friend of mine decided he wanted to design a simple and stupid little game for our closest friends to enjoy.

Here is our concept: You are on the highest point of an Island. Your objective is simple: to push a small cube around the island, and once you get it to a certain point on the island, an explosion in the sky in front of you signifies your victory.

So, we’ve created a small Island world. We’ve figured out through much trial and error how to model in Blender 3D and we have exported a few houses over to populate the Island, and with MUCH help from the Unity Community, we have been able to program the game so that the main character can push the little cube around the Island.

But, we need help in producing the simple script to que the explosion. We know nothing really about how to script ourselves, and in a program where scripting is a key element to creation, this is a problem.

Here’s what we got so far. With help from NickAV on Unity 3D forums, we know that we want to add an Empty to the game world, attach a Box Collider to that, and make it a Trigger. He also supplied us with a basic script to the extent of:

function OnTriggerEnter (other : Collider) {
if (other.name == “WhateverYouCallYourCubeGameObject”) {
//Do something that signifies your victory
}
}

So I ended up with this script below, but there is apparently something that I’m doing wrong. You see, I’m trying to get that particle effect, “Sparks” to play once the Cube Gets into the Box Collider, but apparently I’m doing something wrong.

Any help?

169830--6118--$screen_capture_22_201.png

Also got this error message. I think I’m supposed to parent the particle effect “Sparks” with the Box Collider trigger? How do I do that, exactly?

169832--6119--$screen_capture_23_298.png

you are missing the closing } for the whole function
the if and the function open an { but only the if one is closed again

I would highly recommend to read the docs and check a few scripts to learn more about code formating and especially intend, as that will autosolve such problems

Hey, it looks like you’ve got the right idea. As dreamora pointed out, you’re missing a closing brace. A good idea when writing scripts is to increase your indentation every time you open a curly brace, and decrease every time you close one. This way, mismatched braces will be obvious. For instance, in the code you posted, the missing closing brace is obvious because there is a difference of two tabs (rather than one) between the last line and the one before it:

function OnTriggerEnter(other : Collider)
{
	if (other.name == "Cube")
	{
		hitParticles = GetComponentInChildren(ParticleEmitter);
		hitParticles.emit = true;
}