Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by spacelion88 · Dec 28, 2011 at 09:37 PM · errortutorial

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: http://answers.unity3d.com/questions/46371/error-there-is-already-a-local-variable-with-the-n.html 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?

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

5 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by jamesstrocel · Apr 25, 2012 at 10:49 PM

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

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by kreftdjur · Jan 29, 2012 at 08:16 PM

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.

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image primativ · Jun 12, 2012 at 09:05 PM 0
Share

Thanks, that worked for me.

avatar image
0

Answer by xkater · Apr 06, 2012 at 11:58 PM

http://answers.unity3d.com/questions/199649/3d-platformer-tutorial-.html

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by $$anonymous$$ · Sep 14, 2012 at 04:56 AM

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[i].mainTexture;    
                     newMaterial.color = info.originalMaterials[i].color;
                     newMaterial.color.a = 1.0;
                     info.alphaMaterials[i] = newMaterial;
                 }


http://answers.unity3d.com/questions/46371/error-there-is-already-a-local-variable-with-the-n.html 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 ;)

TLDR This compiles for me using unity 3.5 http://pastebin.com/Jq2xzr28

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by Steve Castaneda · Nov 06, 2012 at 08:33 PM

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

 for (var newMaterial in fade.alphaMaterial)

to:

 for (newMaterial in fade.alphaMaterials)
Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

10 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

John Lemon Tutorial "An error occurred while resolving packages" 0 Answers

2d tutorial error 2 Answers

script error in downloads 1 Answer

Following the wiki.unity scripting tutorial... 1 Answer

Error when I try to run the build in tutorial (roll a ball, tanks, and etc.) 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges