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 uberokeer · Jul 04, 2013 at 10:49 PM · javascriptwontwork

Script Not Working At All.... :) (SOLVED)

I have a bit of a problem... My Script won't work at all! xD I have it applied to my camera The whole Script is:

 var Prefab : Transform;
 function OnGui () {
       if (GUI.Button(Rect(10,10,50,50),"Create")){
             var gos : GameObject[];
             gos = GameObject.FindGameObjectsWithTag("SetObject");
             for (var g in gos){
             if (g.GetComponent.<ControlObject>().isBuild);
             Instantiate(Prefab, g.transform.position, Quaternion.identity);
             }
         }
     }



I don't see anything wrong with it... I even tested to see if it was working by putting: 'Application.Quit();' in the start function and it still didn't do anything :/ once again i have this script on my camera. Anyone have a idea on what may be causing this? Thanks if you can help! :D

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

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by Sjiggle · Jul 04, 2013 at 11:35 PM

well to start with, the following code:

        if (g.GetComponent.<ControlObject>().isBuild);

does not actually do the code you'd expect afterwards. You exit the if, by adding ; at the end. Remove the ; and see if this fixes your code.

Also, I'd advice you to use indents more. It makes code more clear. For example:

 var Prefab : Transform;
 function OnGui () {
     if (GUI.Button(Rect(10,10,50,50),"Create"))
     {
         var gos : GameObject[];
 
         gos = GameObject.FindGameObjectsWithTag("SetObject");
         for (var g in gos)
         {
             if (g.GetComponent.<ControlObject>().isBuild)
                 Instantiate(Prefab, g.transform.position, Quaternion.identity);
         }
     }
 }
Comment
Add comment · Show 6 · 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 uberokeer · Jul 04, 2013 at 11:44 PM 0
Share

no :/ didn't make a difference. Thanks for the advice though xD

avatar image Sjiggle · Jul 04, 2013 at 11:47 PM 1
Share

You are also using the wrong function name. You use OnGui. It's function OnGUI() {

avatar image uberokeer · Jul 04, 2013 at 11:49 PM 0
Share

Oh $$anonymous$$y gosh i can be a idiot some times :P thanks so much, worked perfectly. guess i was na$$anonymous$$g the start function wrong too :P

avatar image Sjiggle · Jul 04, 2013 at 11:51 PM 1
Share

It's a game changer :)

avatar image uberokeer · Jul 04, 2013 at 11:51 PM 0
Share

And what did you mean by: "if (g.GetComponent.().isBuild); does not actually do the code you'd expect afterwards"?

Because what i was trying to do before this problem isn't working :P

Show more comments

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

16 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

Related Questions

Multiple Cars not working 1 Answer

Exporting from Blender to Unity Help! 1 Answer

How do i make a player press a button some time? 2 Answers

BCE0044: expecting }, found 'private'. PLEASE HELP!!!!! 2 Answers

How to call a function from another 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