Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
  • Help Room /
avatar image
-1
Question by Chocolade · Nov 28, 2016 at 02:23 PM · c#scripting problemscript.

I'm getting some errors in the script how can i fix them ?

 float size;
     void Awake()
     {
         Mesh m = new Mesh();
         m.name = "Scripted_Plane_New_Mesh";
         m.vertices = [new Vector3(-size, -size, 0.01f), new Vector3(size, -size, 0.01f), new Vector3(size, size, 0.01f), new Vector3(-size, size, 0.01f)];
         m.uv = [new Vector2(0, 0), new Vector2(0, 1), new Vector2(1, 1), new Vector2(1, 0)];
         m.triangles = [0, 1, 2, 0, 2, 3];
         m.RecalculateNormals();
         GameObject obj = new GameObject("New_Plane_Fom_Script", MeshRenderer, MeshFilter, MeshCollider);
         obj.GetComponent(MeshFilter).mesh = m;
     }


First i'm getting error in every line that have '[' For example:

m.vertices = [new Vector3(-size, -size, 0.01f), new Vector3(size, -size, 0.01f), new Vector3(size, size, 0.01f), new Vector3(-size, size, 0.01f)];

The error is on the [ Invalid expression term '['

Then i'm getting errors on:

MeshRenderer, MeshFilter, MeshCollider and the last MeshFilter all errors are the same:

'MeshRenderer' is a type, which is not valid in the given context

Comment
Add comment · Show 2
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 Mikael-H · Nov 28, 2016 at 02:26 PM 0
Share

This site is not really intended for "please fix my script" services.

avatar image TBruce · Nov 28, 2016 at 08:31 PM 0
Share

You need to follow the current manual docs about meshes and how to create geometry on the fly.

You are currently using five and a half hear old Unity script (July 06, 2011) which is why you are getting errors (pre Unity 3.4.0 which was released July 26, 2011).

This will correct your errors (it does not do or show anything but it does create the mesh)

 private $$anonymous$$eshFilter meshFilter;

 public float size;
 
 void Awake()
 {
     $$anonymous$$esh m = new $$anonymous$$esh();
 
     m.vertices = new Vector3[4] {new Vector3(-size, -size, 0.01f), new Vector3(size, -size, 0.01f), new Vector3(size, size, 0.01f), new Vector3(-size, size, 0.01f)};
 
     m.uv = new Vector2[4] {new Vector2(0, 0), new Vector2(0, 1), new Vector2(1, 1), new Vector2(1, 0)};
 
     m.triangles = new int[6] {0, 1, 2, 0, 2, 3};
     m.RecalculateNormals();
 
     meshFilter  = gameObject.GetComponent<$$anonymous$$eshFilter>();
     if (meshFilter == null)
     {
         meshFilter  = gameObject.AddComponent<$$anonymous$$eshFilter>();
     }
     // assign the mesh to a $$anonymous$$eshFilter
     meshFilter.mesh = m;
 }

Also, Take a look at this free asset made by Unity. It was made for Unity 3.5.6 or higher and you will get the standard Possible incompatibility with Unity 5 error when importing it but Unity will be able to import the scripts and the demos do work.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Mister-Mortal · Nov 28, 2016 at 02:32 PM

For the bracket ('[') part, instead of brackets you need to use curly brackets like this:

 someArray = { firstValue, secondValue, thirdValue };

For second error, you need to use typeof() method like this:

 GameObject obj = new GameObject("New_Plane_Fom_Script", typeof(MeshRenderer), typeof(MeshFilter), typeof(MeshCollider));
Comment
Add comment · Show 2 · 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 Dakwamine · Nov 28, 2016 at 04:09 PM 0
Share

I think you don't even need the new[] when initializing an array with values. Am I wrong?

avatar image Mister-Mortal Dakwamine · Nov 29, 2016 at 08:20 AM 0
Share

You are right, thanks! Updated the answer.

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

252 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Can someone please help me find out what wrong with my code. 1 Answer

How can i disable/enable slowly the blur effect using the blur script ? 0 Answers

How can I give each instance a enum mode from another script ? 0 Answers

How can i make the right choice of implementation of my shooting fire script ? 1 Answer

can i get help please 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