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 nickkunes · Oct 21, 2012 at 01:37 AM · c#javascriptfunctionjavaget component

Calling Functions Within A Script?

So far, I am creating a modeling program, similar to blender in which you can create 3D models.

The only problem ive had is exporting in game. I have a .obj exporter script, yet it is a editor script so it is apparently not usable in game!

The ISSUE I NEED YOU TO FIX IS..Calling this function in the script! -

My Code Of Thingy That I Need To Access :

 using UnityEngine;
 using System.Collections;
 using System.IO;
 using System.Text;
  
 public class ObjExporter : MonoBehaviour {
 
 public ObjExporter script;
 public GameObject ToBeExported;
  
     public static string MeshToString(MeshFilter mf) {
         Mesh m = mf.mesh;
         Material[] mats = mf.renderer.sharedMaterials;
  
         StringBuilder sb = new StringBuilder();
  
         sb.Append("g ").Append(mf.name).Append("\n");
         foreach(Vector3 v in m.vertices) {
             sb.Append(string.Format("v {0} {1} {2}\n",v.x,v.y,v.z));
         }
         sb.Append("\n");
         foreach(Vector3 v in m.normals) {
             sb.Append(string.Format("vn {0} {1} {2}\n",v.x,v.y,v.z));
         }
         sb.Append("\n");
         foreach(Vector3 v in m.uv) {
             sb.Append(string.Format("vt {0} {1}\n",v.x,v.y));
         }
         for (int material=0; material < m.subMeshCount; material ++) {
             sb.Append("\n");
             sb.Append("usemtl ").Append(mats[material].name).Append("\n");
             sb.Append("usemap ").Append(mats[material].name).Append("\n");
  
             int[] triangles = m.GetTriangles(material);
             for (int i=0;i<triangles.Length;i+=3) {
                 sb.Append(string.Format("f {0}/{0}/{0} {1}/{1}/{1} {2}/{2}/{2}\n", 
                     triangles[i]+1, triangles[i+1]+1, triangles[i+2]+1));
             }
         }
         return sb.ToString();
     }
     
     void OnGUI () {
     if(GUI.Button(new Rect(60,290,25,200),"Export Creation As .Obj"))
         
     }
  
     public static void MeshToFile(MeshFilter mf, string filename) {
         using (StreamWriter sw = new StreamWriter(filename)) 
         {
             sw.Write(MeshToString(mf));
         }
     }
 }

Basically, I need to call this function at the bottom of the script from a C#, (I could also do it from a JAVA script if thats the only thing you can help with!)

CALL THIS FUNCTION...

  public static void MeshToFile () {
Comment
Add comment · Show 1
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 Noah-1 · Oct 21, 2012 at 02:55 AM 0
Share

this is confusing,you just need to call the function at the top? if so, just use void Awake(){$$anonymous$$eshToFile();}

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Loius · Oct 21, 2012 at 04:29 AM

Just don't put that function in an editor script. You can call things from other places.

ClassName.StaticFunctionName()

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 nickkunes · Oct 21, 2012 at 04:34 AM 0
Share

Called it using GetComponent... Now how can I make it export a whole variable like..

public static GameObject ToBeExported = GameObject.Find("ToBeExported");

avatar image Loius · Oct 22, 2012 at 08:49 PM 0
Share

$$anonymous$$yType thing;

thing = GetComponent($$anonymous$$yType);

thing.variable = "hello"

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

11 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

Related Questions

How to call a c-sharp function from javascript? 1 Answer

Need help with enum and stuff (right, left click) in JavaScript 0 Answers

get component javascript from a c# script 3 Answers

Convert this line of javascript to C# (easy) 1 Answer

Calling JS Static Function from C# Script 1 Answer


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