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 Jammer3000 · Jun 18, 2014 at 01:16 AM · javascripterrortransform

Error: not a member of 'UnityEngine.GameObject[]'.

Hi the code below is giving me this error and I can't seem to figure out why I think its from assigning something with the array wrong but can' t figure why it gives me the error below?

Code:

 #pragma strict
 
 var birdAnimator : Animator;
 var electricityParticleGameObject : GameObject;
 var scoreValue = 1;
 var script : Move_Left_Script;
 var scoreControlScript : Score_Control_Script;
 var coinBurstParticles : GameObject;
 var magnetGlowParticles : GameObject;
 var coins : GameObject[];
 var trigger = false;
 var speed : float;
 
 
 function Start ()
 {
     for (var i : int = 0; i < 7; i++)
     {
         coins = GameObject.FindGameObjectsWithTag("Coin");
     }
 }
 
 function OnTriggerEnter2D(other : Collider2D)
 {
     
     if (other.tag == "EvilCloud")
     {
     
 //        script.pauseEvilCloudTrigger = true;
         // Activate bird shocking animation
         birdAnimator.enabled = true;
         // Trigger for update function to make sure bird hit cloud before it runs electricity shocking effect
         electricityParticleGameObject.active = true;
         // Destroy Bounce Controller Script on Bird so it disables bouncing from the players input
         Destroy(GetComponent(Bounce_Controller_Script));
         // Destroy Rigidbody so Bird doesn't fall right away
         ShockPauseFall();
         // Set High Score
         scoreControlScript.SetHighScore();
         
         Debug.Log("Player hit evil cloud. End Game!");
     }
     
     if (other.tag == "Coin")
     {
         // Spawns coin burst particles at the location of where the coin was hit and then destroys the particle system after 2 seconds
         var coinBurstClone : GameObject = Instantiate(coinBurstParticles, other.transform.position, Quaternion.identity);
         Destroy(coinBurstClone, 2);
         // Add a point to the current score when coin is hit and also update high score if its lower then current score
         // then disable renderer and collider2D and it gets renabled when it repostions in Coin Spawner Script
         Score_Control_Script.currentScore += scoreValue;
         other.gameObject.renderer.enabled = false;
         other.gameObject.collider2D.enabled = false;
         
     }
     
     if (other.tag == "Magnet")
     {
         magnetGlowParticles.active = true;
         other.gameObject.renderer.enabled = false;
         other.gameObject.collider2D.enabled = false;
         trigger = true;
         Debug.Log("Magnet hit bring that ish!");
         }
 }
 
 function Update () 
 {
     var step = speed * Time.deltaTime;
     
     if (trigger == true)
     {
          coins.transform.position = Vector3.MoveTowards(coins.transform.position, gameObject.transform.position, step);
     }
 }
 
 function ShockPauseFall () 
 {
     // Destroys rigidbody2D component so bird pauses then waits 2 seconds then adds a rigidbody2d and sets its gravity to 3 so it falls fast
     Destroy(GetComponent(Rigidbody2D));
         
 }

Error:

 Assets/Scripts/Gameplay Functionality Script.js(75,23): BCE0019: 'transform' is not a member of 'UnityEngine.GameObject[]'. 

 Assets/Scripts/Gameplay Functionality Script.js(75,70): BCE0019: 'transform' is not a member of 'UnityEngine.GameObject[]'. 



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

2 Replies

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

Answer by Jammer3000 · Jun 18, 2014 at 03:50 PM

This solved the problem thanks to @tanoshimi for the answer!

 if (trigger == true)
     {
         for(var coin : GameObject in coins){
             coin.transform.position = Vector3.MoveTowards(coin.transform.position, gameObject.transform.position, step);
         }
     }

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
1

Answer by Kiwasi · Jun 18, 2014 at 01:26 AM

On line 73 you call coins.transform

coins is a GameObject[]. Arrays do not have a transform.

To access the transform you need to call coins[i].transform where i is the index of the coin you want to access.

Another way to do this is with foreach (c# code)

 foreach (GameObject coin in coins){
     coin.transform. //do whatever
 }


(As an aside your for loop in the start function is doing you no good. Removing line 17 will give you the exact same result faster.)

Comment
Add comment · Show 7 · 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 Jammer3000 · Jun 18, 2014 at 02:36 PM 0
Share

If I remove the for loop how will I access the coins index by doing coins[i]??

avatar image tanoshimi · Jun 18, 2014 at 02:39 PM 0
Share

The i in coins[i] is the coins index. http://unity3d.com/learn/tutorials/modules/beginner/scripting/arrays

avatar image Jammer3000 · Jun 18, 2014 at 02:40 PM 0
Share

I did what you said deleted the loop and changed the coins.transform to coins[i].transform and now it gives me these two new errors?

 Assets/Scripts/Gameplay Functionality Script.js(74,23): BCE0005: $$anonymous$$ identifier: 'i'.
 
 Assets/Scripts/Gameplay Functionality Script.js(74,73): BCE0005: $$anonymous$$ identifier: 'i'.
avatar image tanoshimi · Jun 18, 2014 at 02:57 PM 0
Share

Well, which coin did you want to move towards?! You need to supply its index from the coins array.

avatar image tanoshimi · Jun 18, 2014 at 03:11 PM 1
Share

So then in Update() you want:

 if (trigger == true)
 {
     for(var coin : GameObject in coins){
         coin.transform.position = Vector3.$$anonymous$$oveTowards(coin.transform.position, gameObject.transform.position, step);
     }
 }
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

22 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 avatar image

Related Questions

Can someone help me fix my Javascript for Flickering Light? 6 Answers

Setting Scroll View Width GUILayout 1 Answer

The name 'Transform' does not denote a valid type ('not found'). Did you mean 'System.Net.Mime.TransferEncoding'? (BCE0018) 3 Answers

BCE0019: 'Add' is not a member of 'UnityEngine.Transform[]' 1 Answer

I can do this in JS or not ??? 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