#Deck

1 messages · Page 1 of 1 (latest)

rustic shell
#

@buoyant crater we should do this in a thread instead of dms since other people may have better ideas on what to do

buoyant crater
#

ok how

rustic shell
#

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.

buoyant crater
#

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

rustic shell
#

yeah its fine

buoyant crater
#

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

rustic shell
#

So you have 2 parents that both have children and you want to see if they have the same children?

buoyant crater
#

yes

#

kind of

rustic shell
buoyant crater
#

can i show you what i mean

rustic shell
buoyant crater
#

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

rustic shell
#

only if they are the same or just destroy it regardless?

buoyant crater
#

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

rustic shell
#

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?

buoyant crater
#

that is what i am trying to do

#

how to i post the code in here that i was trying

#

///cs

rustic shell
buoyant crater
#

its not working

rustic shell
buoyant crater
#

lol i tried

rustic shell
buoyant crater
#

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

rustic shell
#

How is the "kill" button assigned to each child

buoyant crater
#

it is on a base gameobect that is cloned , through instanciate

#

that is placed under a parent

#

actually under both parents

rustic shell
#

I'm trying to think of a way to do it without reworking the system

buoyant crater
#

so if they press the button it destroys both just as i created the,

#

them

#

no doubt

rustic shell
#

Can I see how you are instantiating them?

buoyant crater
#

it is easy button press , instacate(gameobject, position, rotation)

rustic shell
#

Oh so they are generated from a button press

buoyant crater
#

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

rustic shell
buoyant crater
#

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

rustic shell
buoyant crater
#

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);

rustic shell
#

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

buoyant crater
#

i see

rustic shell
#

so we are adding it to a list of game objects

#

I'm still thinking about it and i think its not exactly right

buoyant crater
#

no doubt

rustic shell
#

Ok scratch the id number idea I have a better one

buoyant crater
#

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

rustic shell
#
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

buoyant crater
#

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

rustic shell
#

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

buoyant crater
#

i see

#

that is not a bad idea, to have it as a string rather then gameobjects

rustic shell
#

since you can add them to a list easily

buoyant crater
#

yeah i will try what i am coding give me sec and i will try it

rustic shell
#

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

buoyant crater
#

yes i am

#

ill send a screen shot of what i did if ok

buoyant crater
#

i so way over thought this big time i think i am trying a differnt approch

buoyant crater
#

i broke my game lol

#

thank you for your help today i appreciate your time