#Access Data of specific SO in array?
1 messages · Page 1 of 1 (latest)
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
alright
yea
gimme a sec
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?
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
thats a very good point
well theyre not specifically set private wouldnt they be public then
then you would get Recipies[PageCount].RecipeName
no they will always be set to private
but this doesnt display 2 pages at the same time does it
it does
im confused
that is why we increment twice
first part is the left page
and the 2nd part is the right pagge
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?
i was planning on having a little button in both corners that sets the pagecount +2 or -2 depending on the direction
it is basicly PageCount += 1;
same story just increment pagecount by the number you want
oh wait so does this function both display the object that is in the correct slot and also turn the page?
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?
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
jup!
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