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 DarthPork · Jun 16, 2014 at 09:51 PM · javascripterrorgetcomponent

'name' is not a member of Object (js)

Hello all, first off I'm just learning Unity so I'm probably doing something dumb, but: this code was working before, now I have to comment out the lines below to still instantiate correctly (which is place 4 rows of cards, each 12 cards high ), otherwise it only puts one card down instead of 48. ** When the commented sections below wasn't throwing an error, all that was done was removed the 'clcne' in hierarchy and tacked on a name (no big deal), but the If statement was only allowing the first row of cards to be clicked on (disabled script in all other instantiated cards) which is core functionality.

[code] #pragma strict var cardCounter = 0;

 function CreateLeftLane (lanename) {
         var i : int = 0;
         var pos = .2;
         var cardNumber = 1; // assigning numbers, 1-12+ going up row
         for (i = 0; i < laneLength; i++) 
         {
             //pick a random item in array
             var randNum = Random.Range (0, (prefabArray.Length));
             var randCard = prefabArray[randNum];
             Debug.Log ("Rolled a " + randNum);
             Debug.Log ("Card is " + randCard);
             var camerapos = Vector3(.34, 1.58, 0);
             var cardstartpos = Vector3(pos,.8,.4);
             if (lanename == "one") 
             {
             cardstartpos = Vector3(pos,.8,.4);   //place lane 1
             var cardLane = "LaneA-";
             }
             else if (lanename == "two")
             {
             cardstartpos = Vector3(pos,.8,.15);   //place lane 2
             cardLane = "LaneB-";
             }
             else if (lanename == "three")
             {
             cardstartpos = Vector3(pos,.8,-.15);   //place lane 3
             cardLane = "LaneC-";
             }
             else if (lanename == "four")
             {
             cardstartpos = Vector3(pos,.8,-.4);   //place lane 4
             cardLane = "LaneD-";
             }            
             //var newCard : Transform;
             var newCard = Instantiate(randCard, cardstartpos, Quaternion.AngleAxis(270, Vector3.up));
 //            newCard.name = newCard.name.Replace("(Clone)","").Trim();   // take "Clone" off
 //            newCard.name = newCard.name + "                 " + cardLane  + cardNumber;                   // add a number to it
 
 //            if (cardNumber != 1) {      //only card on first row clickable
 //                newCard.GetComponent(FliponClick).enabled = false;
 //            }
             cardNumber++;
             pos += .2;
             cardCounter++; // track # of cards
 
         }
     }

[/code]

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 DarthPork · Jun 16, 2014 at 09:50 PM 0
Share

as a note, if uncommented I get these 2 errors: 'name' is not a member of 'Object'. or 'GetComponent' is not a member of 'Object'.

1 Reply

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

Answer by fafase · Jun 16, 2014 at 09:57 PM

line 35:

 var newCard :GameObject = Instantiate(randCard, cardstartpos, Quaternion.AngleAxis(270, Vector3.up));

Instantiate returns an Object, since UnityScript does the typing for you, newCard ends up being an Object instead of GameObject. Explicitely defining it for GO does the cast and makes it a GO.

C# would not have let you get away with it in the first place.

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 DarthPork · Jun 16, 2014 at 10:03 PM 0
Share

you're my hero, thank you!

avatar image Kiwasi · Jun 16, 2014 at 10:09 PM 0
Share

Actually C# does let you use the var type. I'm pretty sure you could get the same problem in c#.

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

2 People are following this question.

avatar image avatar image

Related Questions

[JS] - GetComponents (No appropriate version) 1 Answer

BCE0044 expecting ), found 'script' and BCE0043 unexpected token ) 2 Answers

"Object reference not set to an instance of an object" Error 1 Answer

How to make animations only play with script? 1 Answer

Calling a function from another script issue 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