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 09:10 PM · errorunknown

Anyone know what's wrong with this code? (SOLVED)

I keep getting a error on this code. It says: 'isBuild' is not a member of 'UnityEngine.Component'. it occurs on line 15 For some reason I can't get a straight answer, Thanks if you know.

 #pragma strict
     var Prefab : Transform;
     function Start  () {
     
     }
     
     function Update () {
     
     }
     function OnGui  () {
     if (GUI.Button (Rect (10,10,150,100), "Create")) {
     var gos : GameObject[];
         gos = GameObject.FindGameObjectsWithTag("SetObject");
         for (var g in gos){
         if (g.GetComponent("here the name of the Script").isBuild);
         Instantiate(Prefab, g.transform.position, Quaternion.identity);
         Application.Quit();
     }
         }
             }
Comment
Add comment · Show 21
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 InfiniBuzz · Jul 04, 2013 at 09:26 PM 1
Share

Try

I cannot type the proper brackets on mobile lol Look here http://docs.unity3d.com/Documentation/ScriptReference/GameObject.GetComponent.html

You have to define the type like in the second example

avatar image InfiniBuzz · Jul 04, 2013 at 09:31 PM 1
Share

I edited my comment sorry ;) you have to use the 'bihger than' and 'smaller than' brackets which i cannot type on mobile.

avatar image InfiniBuzz · Jul 04, 2013 at 09:35 PM 1
Share

GetComponent.+scriptName+() Ins$$anonymous$$d of the + use smaller than and bigher than symbols Hope you understand

avatar image Graham-Dunnett ♦♦ · Jul 04, 2013 at 09:39 PM 1
Share

@InfiniBuzz means

 GetComponent.<scriptName>()
avatar image InfiniBuzz · Jul 04, 2013 at 09:40 PM 1
Share

Haha yep thanks ;)

Show more comments

4 Replies

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

Answer by Graham-Dunnett · Jul 04, 2013 at 09:52 PM

GetComponent() returns a Component. That's a Unity base class. When you create a script, it inherits from Component. The script you create has extra members, of course, so, in your example, it looks as though your script has a member called isBuild. When you use GetComponent() to find your script, you can do:

 var s : YourScript = g.GetComponent(YourScript) as YourScript;
 if (s.isBuild) {
     //blah

This grabs the component, and casts it to YourScript, which has the isBuild member. Alternatively you can use the generic version:

 var s : YourScript = g.GetComponent.<YourScript>();
 if (s.isBuild) {
     //blah

which does the exact same thing. Obviously you'd check that s has a value before using it.

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 trs9556 · Jul 04, 2013 at 09:46 PM

I don't use JS and I'm going on a limb here but try something along the lines of:

 if (GUI.Button (Rect (10,10,150,100), "Create")) {
     var gos : GameObject[];
     gos = GameObject.FindGameObjectsWithTag("SetObject");
     for (var g in gos){
         var temp : ScriptName;
         temp = g.GetComponent("here the name of the script");
         if(temp.isBuild()){
             Instantiate(Prefab, g.transform.position, Quaternion.identity);
         }
         Application.Quit();
     }
 }
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 uberokeer · Jul 04, 2013 at 10:25 PM

Okay I have another problem :p 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 · 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 JohnnySunshine · Jul 05, 2013 at 12:12 PM 1
Share

I think 'OnGui' should be 'OnGUI'. Also, there's a semicolon at the end of line 7, watch out for that! :)

avatar image uberokeer · Jul 05, 2013 at 03:38 PM 0
Share

Yeah that's actually what the problem was. I resolved it earlier. Thanks though :)

avatar image
0

Answer by testandi · Jul 05, 2013 at 01:02 PM

can you see in the inspector that when running the scene you have an object with tag "SetObject"?

Im editing my own answer now as somebody said it is not an answer but a comment

it could be that the code is calling a tag which is not existing.

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 Bunny83 · Jul 05, 2013 at 01:22 PM 1
Share

That's not an answer! If you want to post a comment, use the "add new comment" button below the post you want to comment on.

Answers should answer the question.

avatar image uberokeer · Jul 05, 2013 at 03:38 PM 0
Share

Well i got everything to work, I found out what the problem was, that i spelled it 'OnGui' ins$$anonymous$$d of 'OnGUI'

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

21 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

Related Questions

Multiple Cars not working 1 Answer

BCE0044: expecting EOF, found '}'. 1 Answer

Assets/cubeAI.js(2,11): UCE0001: ';' expected. Insert a semicolon at the end. 1 Answer

Picking up an object 1 Answer

SendMessage illogical errors 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