3D Platformer Tutorial -

I have been following along the tutorial word for word, have restarted several times, redownloaded and reinstalled.

When it says to add the SpringFollowCamera script under the NearCamera object in the hierarchy I am unable to do so. It says "there is already a local variable named “NewMaterial” in the FadeoutLineofSite script.

I’ve opened that script in notepad and played around with the lines containing “NewMaterial.” I have some minor experience with html, C+, C# & javascript, but I’m having to refresh my memory a lot and read other tutorials. But so far I haven’t been able to figure this out. This thread: Error "There is already a local variable with the name 'obstacle'." How can I make it work? - Questions & Answers - Unity Discussions seems most helpful so far, but hasn’t really solved my problem yet.

Keep in mind I haven’t done anything different than what the PDF says to do. I just downloaded everything, followed along exactly, and ran into this error which no one else seems to have had from the tutorial. I am confused as to why I am the only one having this problem. Is it possible I installed Unity wrong?

open the culprit (Assets/Scripts/Camera/FadeoutLineOfSight.js) file by double clicking it in the project view

go to line 125, should look like this:
for (var newMaterial in fade.alphaMaterials)
Destroy(newMaterial);

rename the newMaterial variable on both lines to a name of your liking. e.g.:
for (var newMaterialA in fade.alphaMaterials)
Destroy(newMaterialA);

save. press play. voila.

Change the name of newMaterial in FadeoutLineOfSight.js at lines 125 and 126 to something like newMaterial1 and the project should compile.

I was having the same error and thought about changing the name to newMaterialA to make it compile, but I thought it might create another problem(since newMaterialA isn’t declared, I thought it would break the original functionality by changing the name…is this correct?)

“// All alpha materials are faded back to 100% // Thus we can switch back to the original materials”

Don’t know if it’s important, or what it does (I’m new) but wanted to preserve it. Assuming it does something, otherwise the creator wouldn’t have put it there.
So instead of changing ‘var newMaterial’ to ‘var newMaterialA’, I changed it to (line 125):

for (newMaterial in fade.alphaMaterials)
Destroy(newMaterial);

That should let it continue doing ‘it’s thing’. I think the problem was FadeoutLineofSight declaring the variable newMaterial more than once (i.e. var NewMaterial) because it’s already declared earlier in the script with (line 70):

for (var i=0;i<info.originalMaterials.length;i++)
				{
					var newMaterial = new Material (Shader.Find("Alpha/Diffuse"));  //This is where newMaterial is declared for the first (and only) time, don't declare it anywhere else! or you will be eaten by a grue.
					newMaterial.mainTexture = info.originalMaterials*.mainTexture;	*

_ newMaterial.color = info.originalMaterials*.color;_
_
newMaterial.color.a = 1.0;_
_ info.alphaMaterials = newMaterial;
}
[Error &quot;There is already a local variable with the name 'obstacle'.&quot; How can I make it work? - Questions & Answers - Unity Discussions][1] helped me figure out what was going wrong, it’s compiling fine for me after simply removing ‘var’ from in front of newMaterial at line 125&126.
Someone mentions how JS (and therefore Unityscript, I think) handles scope differently than C#, which is why it doesn’t work to declare the same variable a second time in JS, even if it’s inside an If statement even though the code block won’t run unless the condition is met. I don’t understand scope yet, so this might not be correct, I’m guessing :wink:
TLDR This compiles for me using unity 3.5_

_[Unity3d FadeoutLineOfSight - Pastebin.com][2]
[1]: http://answers.unity3d.com/questions/46371/error-there-is-already-a-local-variable-with-the-n.html*_

_*[2]: http://pastebin.com/Jq2xzr28*_

On line 125 of FadeoutLineOfSight.js, change this (remove var):

for (var newMaterial in fade.alphaMaterial)

to:

for (newMaterial in fade.alphaMaterials)