#Deck
1 messages · Page 1 of 1 (latest)
ok how
im reading through what you said
im trying to have a icon button that i press, when i do , it compares its child position, as in (0) if that is it, to a deck child position and if they are both (0) then destroy both.
so sorry
i thought deck was someone else telling me to do that lol
i have not been on this discord
so i am a bit confused and i never ask for help really
yeah its fine
well the ok how was kinda rude sounding
and i am far from that
and i dont mind screen sharing
to show more of what i mean
So you have 2 parents that both have children and you want to see if they have the same children?
can you elaborate?
can i show you what i mean
you can explain it\
ok
so i have deck a as a parent and deck b as a parent
deck b has a button on it that represents the card in deck a
when i press the button in b, i want to destroy the card in a
only if they are the same or just destroy it regardless?
they will both have the same child position in the heigharcy as they are both instanciated in the same order at the same time
only if they are in the same position as a child
it be so much eaiser to show you but i cant complain your helping or trying to which i really appricate
Do you have a system in place that can find out which position a child is in? like if its child 1, 2 or 3?
that is what i am trying to do
how to i post the code in here that i was trying
///cs
you can copy the thing in #854851968446365696
its not working
use a paste site in #854851968446365696
lol i tried
the links in the green embed
i have been trying from what i know
i am so sorry
for the screen shot i did not see it was not allowed unless asked
How is the "kill" button assigned to each child
it is on a base gameobect that is cloned , through instanciate
that is placed under a parent
actually under both parents
I'm trying to think of a way to do it without reworking the system
so if they press the button it destroys both just as i created the,
them
no doubt
Can I see how you are instantiating them?
it is easy button press , instacate(gameobject, position, rotation)
Oh so they are generated from a button press
yes
i am tying to get it to be universal
and hardcode it
since i want it to be a variable int that is equal to the getchild(i)
so to speak
that way if i press the button, it says ok i am child(i) and look for child(i) the other parent and if i am equal to that child(i) destroy both
yeah the main thing is to figure out what "i" the objects being clicked on is
exactly
i have been trying to have it getchild(i) = this.gameobject.transform, but that wont work just to say i have tried everything that i can think of which made me give in and reach out
i tried a foreach loop
for loops
arrays
lists
and i fail every go
i really appreciate your time by the way even if it is not figured out
Oh so you are familiar with lists?
yes
i just cant find a way to index the child to its getchild position
public list<int> children = new list <int>();
for (i = 0 xyz on the for loop
then
children.add(child);
When you instantiate them assign each child a number: (might look like this)
int number = 0;
//if you have a loop itll go here
GameObject child = Instantiate(prefab, pos, rot);
//Then add the child to a list of game objects
child.GetComponent<CardScript().childPosition = number;
number++;
when you instantiate an object, it gives a reference you can use
i see
so we are adding it to a list of game objects
I'm still thinking about it and i think its not exactly right
no doubt
Ok scratch the id number idea I have a better one
no doubt
i thought about the id number as well
i was going to make the gameobject a scriptable object, give it an id , the compare it to the id of the other object since they would be the same but then id have to chage alot of my system
if you have a loop itll go here
GameObject child = Instantiate(prefab, pos, rot);
Then add the child to a list of game objects
On your destroy button
use List.FindIndex(childObject);
childObject being the object the button is on
then once you find the index, you can search the opponents list of children to destroy that index. make sure to remove that object from the opponents list as well
might be a bit confusing but you can find out the position of a game object in a list/array using List.IndexOf
so you know which position it is
then use that int to destroy the object of the other list
There's probably a cleaner way to do it, but it shouldn't change you system that much since I'm pretty sure lists are dynamic, meaning that removing element 4 means that element 5 becomes 4 and etc
i see
i will have to try this out
right now i am writing the list so that they populate, then i will try this list.findindex
Maybe a less confusing explanation:
List<string> playerList= new List<string>() {a, b, c, d, e};
List<string> enemyList= new List<string>() {a, b, c, e, e};
int num = playerList.IndexOf(c); //returns 2
Destroy(enemyList<num>);
enemyList.Remove(num);
I'm not familiar with the lists syntax so I probably got some of it wrong
Thats just an example, I think game objects would work better though
since you can add them to a list easily
yeah i will try what i am coding give me sec and i will try it
I don't quite remember the list Add and remove methods so its partly just pseudocode
A more unity related example
GameObject child = Instantiate(prefab, pos, rot); //gets GameObject ref from Instantiate
playerListOfGameObjects.Add(child); //adds ref to a list
button:
int num = playerList.IndexOf(objChildIsOn);
Destroy(enemyList[num]); //destroys object
enemyList.Remove(num); //removes destroyed object from list
^ @buoyant crater you'd add all of the player and enemy objects to their corresponding lists
i so way over thought this big time i think i am trying a differnt approch