Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 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 /
  • Help Room /
avatar image
0
Question by Kryloth · Mar 04, 2020 at 02:52 PM · arrayarraysarray of gameobjectsarraylist

How to compare a position of an object within an array

Hello, so i was trying to compare a position of an object within an array with an int variable that i have

I have this variable called stagePos, and i wanna use it to find an object that has the same value for its position in an array.

If the stagePos is 1, then i want to find an object that has the position of [1] in an array and do something with it as well as do something with the other object in that array because they don't have the same value as stagePos

 if(stage[i] != stage[stagePos]){
                 Vector3 pos = stage[i].transform.position;
                 pos += new Vector3(0f, -4f * Time.deltaTime , 0f);
                 stage[i].transform.position = pos;
                 stageScript.Invinsible(true);
             }
             else if(stage[i] == stage[stagePos]){
                 Vector3 pos = stage[i].transform.position;
                 pos += new Vector3(0f, 4f * Time.deltaTime, 0f);
                 stage[i].transform.position = pos;
                 stageScript.Invinsible(false);
         
             }


So that is the code, but i still can't figure out on what do i need to do to compare it

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

Answer by tormentoarmagedoom · Mar 04, 2020 at 03:51 PM

Hello.

I'm not sure to understand you.

StagePos i an integrer? where it comes from? You want to compare if stage[i] position is the same as stage[stagePos] position?

Then just

 if (stage[i].transform.position == stage[stagePos].transformposition)

or you need to find something like

¿which element from all stage[] objects have the same trasfrom as stage[stagePos]?

then do something like:

 void findStageWithSamePos()
 {
 foreach (GameObject OneStage in stage[])
 {
 if (OneStage.transform.position == stage[stagePos])
     {
      // DO something here, because OneStage position will be same as stage[stagePos]
      }
 
 }


Comment
Add comment · Show 3 · 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 Kryloth · Mar 04, 2020 at 04:08 PM 0
Share

No it's not like that

Basically i want to check, when i use stagePos its default value is 0, and i get an input from user to increment it to 1, i wanna check whether there's an object in the stage array that has the position of 1, if there is then i wanna do something to it but i also wanna do something to the other object that has a different position after it did something, in this case is just moving the object around i want the code to just sit there and wait until there's a change with the stagePos value, and then do it all over again

avatar image tormentoarmagedoom Kryloth · Mar 04, 2020 at 04:43 PM 0
Share

$$anonymous$$an.. your explanation si not very good...

"there's an object in the stage array that has the position of 1" of 1 what ? position is a vector, not a number. how can have position of 1? If there is an object with the same position of first element from the array?

You have multiple problems., go step buy step. TRy to say in one sentece what 2 elements need to compare, and talk correctly, using the correct words. If not is almost impossible to help you. And this its like a conversation, and shouldnt. Pelase remake the post giving the correct info. (we are close to solve your problem :D)

avatar image Kryloth tormentoarmagedoom · Mar 04, 2020 at 11:53 PM 0
Share

Okay it's like this, you know that when you put something in an array, that something has an index position within an array as [0]. let's say that i have a public GameObject[] food; if i put noodles inside the food variable, i can access the noodles with just food[0] right ?

So that's what i'm trying to do, i want to access an index position of an object within the array, not the transform position of the object itself because i want to basically do something with the object that i choose the index position with a stagePos variable

So that when the stagePos value is [0], it will access the food[0], and anything that isn't food[0] like food[1], food[2] won't do anything

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

217 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 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 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 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 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 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 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 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 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 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

Dynamic buttons with an array from firebase URL links 0 Answers

Moving spawned enemies randomly towards several pre-defined positions 1 Answer

Array problem, I'm novice 1 Answer

Storing a Gameobject from array into a Gameobject variable giving NullReferenceException 3 Answers

Problems with arrays (or how to rewind objects' states) 0 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