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 SimonDiamond · Oct 17, 2012 at 11:40 PM · c#gameobjectlistmovingspecific

Moving a specific gameobject in a list

As the titles says, i'm trying to move a specific gameobject in my list. What my code ends up doing is only moving the first gameobject added to the list. Here's my code.

     public List<GameObject> Enemies = new List<GameObject>();
     public GameObject Enemy;
     public float TimeLimit;
     public float Timer;
     public float Speed;
     public int count;
 
     void Update () 
     {
         Timer++;
         if (Timer >= TimeLimit)
         {
             Enemies.Add(Enemy);
             GameObject.Instantiate(Enemies[count], Enemy.transform.position, Quaternion.identity);
             count = count + 1;
             Timer = 0;
         }
         if (Enemies.Count == 5)
         {
             Enemies[2].transform.Translate(Vector3.up * Speed * Time.deltaTime);
         }
     }

Anyone have any suggestions? Thanks for reading!

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
0
Best Answer

Answer by whydoidoit · Oct 17, 2012 at 11:41 PM

You want to do

   Enemies.Add(Instantiate(Enemy, Enemy.transform.position, Quaternion.identity));

The count will be Enemies.Count

Comment
Add comment · Show 5 · 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 SimonDiamond · Oct 18, 2012 at 12:28 PM 0
Share

It gives me two errors :( "cannot convert `UnityEngine.Object' expression to type `UnityEngine.GameObject'" and The best overloaded method match for `System.Collections.Generic.List.Add(UnityEngine.GameObject)' has some invalid arguments

avatar image whydoidoit · Oct 18, 2012 at 12:31 PM 0
Share

Sorry - that's:

  Enemies.Add(Instantiate(Enemy, Enemy.transform.position, Quaternion.identity) As GameObject);
avatar image SimonDiamond · Oct 18, 2012 at 04:55 PM 0
Share

Worked like a charm! Thanks, much appreciated!

avatar image whydoidoit · Oct 18, 2012 at 05:57 PM 0
Share

Great news! Glad you got it working.

Can you mark is as answered by clicking the tick? $$anonymous$$eeps the board clean.

avatar image SimonDiamond · Oct 19, 2012 at 09:22 PM 0
Share

Trying to find the way to do it....

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

10 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

Related Questions

Subtracting the position of transform from the position of Game Objects in a list. 1 Answer

How to select an Game Object from an Item List 0 Answers

C# List foreach problem 1 Answer

How to select the Nth gameObject in a list and put it into a gameObject variable 1 Answer

Keep list of GameObjects between scenes 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