#Access Data of specific SO in array?

1 messages · Page 1 of 1 (latest)

cold bridge
#

oh like this

#

lol

normal steppe
#

there we go xD

#

could you show me your array?

cold bridge
#

the first screenshot is the array, the second screen is the scriptable object type that is being used in that array

#

the last pic is what i want to do

#

I want to basically grab the first 2 items of the array

#

object 0 and object 1

#

and then if the page gets turned to the right select the next 2 items

#

imagine its a book

#

and the objects have to be displayed on the pages correctly

normal steppe
#

alright

cold bridge
#

yea

normal steppe
#

gimme a sec

cold bridge
#

I understand taht like recipies[0] is the first object that is in the array recipies

#

because it starts counting at 0 right

#

but

#

but i dont know how to access anything that is contained in that scriptable object

#

Access Data of specific SO in array?

normal steppe
#

I would do something like this:

private int PageCount = 0;
public void OnPageChange()
{
  //First Page
  
  RecipeLeft.SetActive(true);
  RecipeLeft.GetCompnent<TMP_Text>().SetText(Recipies[PageCount])
PageCount ++;
//2nd page
  RecipeRight.SetActive(true);
  RecipeRight.GetCompnent<TMP_Text>().SetText(Recipies[PageCount])
PageCount ++;
  
}

#

something like this should work

#

ifcourse this is increment only

#

if you want it to go down you can add the same code but instead use PageCount--;

#

not sure btw but i think you SO objects need to be public for the script to find them

cold bridge
#

thats a very good point

#

well theyre not specifically set private wouldnt they be public then

normal steppe
#

then you would get Recipies[PageCount].RecipeName

#

no they will always be set to private

cold bridge
#

but this doesnt display 2 pages at the same time does it

normal steppe
#

it does

cold bridge
#

im confused

normal steppe
#

that is why we increment twice

#

first part is the left page

#

and the 2nd part is the right pagge

cold bridge
#

and pagecount goes up when turning to the right page and down when turning to the left page with to make this work right

#

would it go up 2 when turning the page?

normal steppe
#

it goes up 2 when turning the page

#

that is what PageCount++ does;

cold bridge
#

i was planning on having a little button in both corners that sets the pagecount +2 or -2 depending on the direction

normal steppe
#

it is basicly PageCount += 1;

#

same story just increment pagecount by the number you want

cold bridge
#

oh wait so does this function both display the object that is in the correct slot and also turn the page?

normal steppe
#

yes

#

Recipies[PageCount] this part in specific is your recipe

cold bridge
#

well so this is the function to turn to the next page then theoretically right to the right side

#

so i have to do the opposite when turning to the left?

normal steppe
#

exactly!

#

then it would be PageCount--;

cold bridge
#

so maybe I would call this function OnPageRight();
and another one with OnPageLeft(); that contains --;

#

so that i can then have 2 ui buttons that call left or right depending on what button is used

normal steppe
#

jup!

cold bridge
#

please explain though how it selects the correct recipe

#

the very first page would be object 0 out of the array?

#

and then 1 and so on?

#

is that because initially we set pagecount to 0 it would get the same recipe that is associated with that page?

#

Wow thats so cool I had no idea I could have another name/item link to a number and just put that name/item behind the array object to collect the correct array object