- Home /
is it possible to give only part of array through []
what I'm trying to do is not creating loads and loads of arrays but 1 BIG array and separate it by numbers so to say
my structure
using UnityEngine;
using System.Collections;
public struct ExpandRect {
public void ExpandF(Rect FirstRect, ref Rect[] Expandable, ref float LastRectY){
int i=0 ;
for (; i<Expandable.Length; i++) {
Expandable[i] = new Rect (FirstRect.x + FirstRect.width, (FirstRect.y + Expandable[i].height * i) ,Expandable[i].width, Expandable[i].height);
}
LastRectY = Expandable[i].y + Expandable[i].height;
}
}
and I'm calling the structure
public Rect[] SkillButtonRec = new Rect[200];
public float SHeight = 20 ;
public float SWidth = 50 ;
public ExpandRect ExpaRec;
float lastpos = 0;
ExpaRec.ExpandF(new Rect(0,0,SWidth,SHeight), ref SkillButtonRec[1 - 3], ref lastpos);
if (SkillNameb[0] = GUI.Toggle((SkillButtonRec[0] = new Rect(0,0,SWidth,SHeight)) ,SkillNameb[0], SkillName[0] )){
// GUI.Toggle(SkillNameb[1], SkillName[1]);
// GUI.Toggle(SkillNameb[2], SkillName[2]);
// GUI.Toggle(SkillNameb[3], SkillName[3]);
this:
Rect(0,0,SWidth,SHeight), ref **SkillButtonRec[1 - 3]**, ref lastpos);
is what I'm trying to achive is it possible or I must create loads of arrays and call give them whole afterwords?
thanks in advance
yes I know I could use 50 times begin horizontal and begin vertical but that gives me headache especially for so complicated gui I want to have this 1 step is easy to make with that but doing it 30 of them is different story
why not add the start and end index you which to expend as arguments?
Answer by GuyTidhar · Feb 26, 2013 at 11:47 AM
public void ExpandF(Rect FirstRect, ref Rect[] Expandable, ref float LastRectY, int start, int end)
{
for (int i=start; i<=end; i++)
{
Expandable[i] = new Rect (FirstRect.x + FirstRect.width, (FirstRect.y + Expandable[i].height * i) ,Expandable[i].width, Expandable[i].height);
}
LastRectY = Expandable[i].y + Expandable[i].height;
}
And then when you call it, you'd do:
Rect(0,0,SWidth,SHeight), ref SkillButtonRec, ref lastpos, 1, 3);
By the way, you don't need to use 'ref' when passing objects (non value types) - they are already passed as reference.
an array is always a reference type. float for instance is a value type.
yeah OFC thanks forgot it's already referenced
it completely came in to my sub conscious so I don't need to write too long codes
Your answer
![](https://koobas.hobune.stream/wayback/20220613093433im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
How to set a specific gameobject in an array false when it collides with a trigger. 1 Answer
C# print Array? 1 Answer
Question about FindObjectsOfType 1 Answer