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 emekaryan · Jun 15, 2013 at 08:59 PM · gameobjectiosdynamic typing

IOS Port Error : "GetComponent is not a member of Object"

heres my code snippet:

 #pragma strict
 
 function SelectPiece(){            
 
 // select piece to play
 
     var pieceScore : int[];        // piece move value/score
     pieceScore = new int[4];    // new array
     var pValue : int;            // move value
     var last : int;                // last piece value
     var piece : int;            // piece to play (piece is declared as an int - does unity cast this to object by default? )
     
     switch(game.turn){                    // select playing player
         case PlayerTurn.P1:                    
             if(gameScript.players[1] == Player.cpu){                        // if CPU player
                 for(var x = 0;x < 4;x++){                                    // loop pieces
                     pieceScore[x] = GetPieceScore(gameScript.p1pieces[x]);    // get piece score
                 }
                 for(x = 0;x < 4;x++){                // loop pieces scores
                     pValue = pieceScore[x];            // get piece value
                     if(pValue > last){                // if this piece has greater value then last piece
                         last = pValue;                // set new last best score
                         piece = x;                    // set playing piece
                     }
                 }
                 isSelect = true;                    // set piece selected
                 gameScript.p1pieces[piece].GetComponent("piece1").Click(PlayerTurn.P1);    // i get the error here// CPU play/click on selected piece
             }
             break;

i dont see anyway of casting this to a gameObject without getting the error "unity cannot convert int to UnityEngine.GameObject"

Please help!!! I know there are other post relating to this issue, but none of them directly addresses this issue. Im open to doing hella more research so if there are any links id be happy to explore them. I actually want to learn why this happens also or is it just IOS not supporting dynamic typing?

Thanks Guys!

Comment
Add comment · Show 4
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 Graham-Dunnett ♦♦ · Jun 15, 2013 at 09:00 PM 0
Share

I formatted your code for you. Please learn how to do this for yourself.

avatar image Graham-Dunnett ♦♦ · Jun 15, 2013 at 09:01 PM 0
Share

What is the type of the p1pieces array? The compiler doesn't know what type it is.

avatar image emekaryan · Jun 15, 2013 at 09:08 PM 0
Share

here is how i have declared it in my game.js script

var p1pieces : Array;

thanks for helping with the format. i will learn how to do it myself

piece1 is also explicitly declared as type GameObject

avatar image emekaryan · Jun 15, 2013 at 11:51 PM 0
Share

found a way around the error and it works. So i thought i'd share it.

  var temp1 = gameScript.p1pieces[piece] as GameObject;
 (temp1.GetComponent("piece1") as piece1).Click(PlayerTurn.P1);
 
 

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Eric5h5 · Jun 16, 2013 at 01:17 AM

Never use the Array class; it's slow and untyped. Use built-in arrays or generic Lists instead. Also, never use quotes in GetComponent. That makes it return Object instead of the correct type, among other problems. Just do GetComponent(Piece1).

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

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

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

Problems compiling script for iPhone that don't appear when running in unity. 2 Answers

How to tilt the gameobject based of Input.Acceleration? 0 Answers

EventSystem IDragHandler not working on iOS 1 Answer

dynamic typing in Unity iOS: ...not a member of 'UnityEngine.Component' 2 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