Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4570030
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T19:18:14+00:00 2026-05-21T19:18:14+00:00

I know that with continue you can skip certain parts of scripts, but is

  • 0

I know that with continue you can skip certain parts of scripts, but is there a way to do the same thing with an array? I want that every object is stored in an array, but not the object(which also has the same tag) which wears this script.

var enemies : GameObject[];

function Start(){
    seeEnemies();
}

function seeEnemies():GameObject{
    enemies = GameObject.FindGameObjectsWithTag("enemy");
}

Example:
Enemy 1 has an array which has Enemy 2,3,4.
Enemy 2 has an array which has Enemy 1,3,4.
Enemy 3 has an array which has Enemy 1,2,4.
Enemy 4 has an array which has Enemy 1,2,3.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T19:18:15+00:00Added an answer on May 21, 2026 at 7:18 pm

    Probably skipping the add is more expensive than simply adding all, and removing the object afterwards.

    You could also work with indirection: each object ‘knows’ it’s index in the array. When iterating the array, you skip ‘your own’ index:

    var what_to_do = function( index, element ) {
       // do stuff with element
    }
    // handle all elements _before_ this
    var i = 0;
    for( ; i != this.index && i != elements.length; ++i ) {
      what_to_do( i, elements[i] );
    }
    ++i; // skip this one
    for( ; i < elements.length; ++i ) {
      what_to_do( i, elements[i] );
    }
    

    The ‘do stuff’ may be encapsulated in an anonymous function, in order not to have to repeat yourself.

    — EDIT —

    Hmmm… and you may even factor out the ‘skip’ function:

    function skip_ith( elements, thisindex, f ) {
       var i = 0; 
       for( ; i != thisindex && i != elements.length; ++i ) {
          f( i, elements[i] );
       }
       ++i;
       for( ; i < elements.length; ++i ) { // note: < because i may be length+1 here
          f( i, elements[i] );
       }
    }
    

    Application:

    for( var i = 0; i != elements.length; ++i ) {
       skip_ith( elements, i, function( index, element ) {
          // do stuff with element
       } );
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I know that it's a subject that can raise a lot of debate, but
I know that there have been plenty of topics describing this topic but I
Can a WinRT app continue to run while Screen Off? I know that a
I know that I should put all the html elements in body tag, but
I know that one can define an 'expected' exception in JUnit, doing: @Test(expect=MyException.class) public
I know that this has already been asked here but the answer (using a
I know that a custom JVM can behave a little differently, and I'm trying
SO Folk, Anyone around these parts know if you can keep Cucumber from cleansing
I know that it is an easy task, but after changing my code it
I know that normally there are no problems using Git from different OSs to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.