Hi, i have an array size 10.
array[1] = a;
array[2] = b;
array[3] = c…
I want to make a random that choose 1 of 3 options that i give
Value = Random.Range[1,4,6];
array[Value];
How can i make it?
Should i use another array?
Hi, i have an array size 10.
array[1] = a;
array[2] = b;
array[3] = c…
I want to make a random that choose 1 of 3 options that i give
Value = Random.Range[1,4,6];
array[Value];
How can i make it?
Should i use another array?
I can’t think of another way:
int[] choices ={1,4,6};
int value = Random.Range(0,3); //the max value isn't inclusive for an integer;
string choice = array[choices[value]];
yea thats what i thought
Thanks,
Do you have any idea how can i make Array of arrays?
I want to make something like this:
choises[1] = choose[1,2,3] (include ints)
You could…
int [] choices = new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
List<int> smallset = new List<int>(choices);
for(int i = 0; i < 7; ++i) {
smallset.RemoveAt(Random.Range(0, smallset.Count));
}
// now, 'smallset' is only 3 long, and 'choices' can be reused.
Array of array of List of List is doable.
List is somewhat similar. Here is a link (kinda like my example): Arrays - C# reference | Microsoft Learn
int [][] nums = new int[3][];
nums[0] = new int[2] {1,2};
nums[1] = new int[3] { 3,4 };
nums[2] = new int[2] { 5, 6};
Notice they don’t have to be the same size.
There is also [,] which is multi-dimensional, I think they call it. I never use that, but it’s an option. They have to be the same size, I’m pretty sure.
Thanks, i actually used another class to make that thing easier for me.
I have another question
public void OnTriggerEnter2D(Collider2D other)
{
if (other.gameObject.tag == "Enemy")
{
a = other.gameObject.GetComponents<NewEnemy>().Attack);
}
}
This code is written in the Players class.
I need to get Enemie’s Attack value , i am trying to use that command but its not so helpful.
Usually i relate the Player to the enemy but in this case there is multipel enemies.
So, what’s not working? Is ‘a’ declared? You have a parenthesis at the end that shouldn’t be there, and if ‘a’ is declared as ‘int’ or whatever appropriate type, that should work, provided 'attack ’ is public
oh and GetComponent shouldn’t have an ‘s’
yup, it was the ‘s’