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 /
This question was closed Mar 02, 2020 at 09:21 PM by Zentiu for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by Zentiu · Mar 01, 2014 at 10:13 AM · c#array

array c# sending info from one script into another scripts array.

Hiya, so here's my problem.

I already know how to make an array, adjust its size, put different stuff in it and access them inside a single script. (making navigational locations for enemy's so they can patrol and such.)

now I want to make a closest enemy script in my selecting script. for that I need to make an array in my existing Selecting script and having other scripts (enemy scripts) send their info to my Selecting scripts array when they are within 100 meters or so and remove themselves from the array when they are further then 100 meters.

I figured out how to select them from my array but actually putting stuff in there from another script is still beyond me.

if you need like examples of what I got so far, just ask and i'll put it in.

hope someone can help me out with this problem.

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

  • Sort: 
avatar image
2
Best Answer

Answer by pafla · Mar 01, 2014 at 12:43 PM

I would recommend, you use a List instead of an array, if you intend to add and/or remove elements frequently. A List would be much faster and easier to use in that case.

One way to do this would be to create public AddEnemy(EnemyInfo) and RemoveEnemy(EnemyInfo) methods in your class containing the array / List. The enemies would then use GetComponent() to obtain the instance of that class and call those two functions, passing their data.

Some Links to help you:

http://www.dotnetperls.com/list http://docs.unity3d.com/Documentation/ScriptReference/GameObject.GetComponent.html http://docs.unity3d.com/Documentation/Manual/GenericFunctions.html

Comment
Add comment · Show 1 · 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 Zentiu · Mar 15, 2014 at 08:12 PM 0
Share

sorry for the delay but I had to learn some extra shit about array's and lists to see if your answer was the answer I was looking for. and it is :) thnx for the help.

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

Distribute terrain in zones 3 Answers

Set default length for an array of elements of a custom class in inspector 0 Answers

How to check if a value exists in an array (C#) 3 Answers

Move files from folder a to folder b 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