- Home /
selected object in array lost in translation
in piece script ::
function OnMouseUp(){
isSelected = true;
if (currentPosition == corner){
var pathSelectorClone = Instantiate(pathSelector, yada yada);
}
}
goes to the pathselector script ::
function OnMouseUp(){
var piece = GameObject.FindWithTag("someTag");
if(piece.GetComponent(SomeScript).isSelected == true){
piece.GetComponent(SomeScript).movePiece();
}
}
which goes back to piece ::
function movePiece(){
(motion logic here)
}
since the piece is a prefab and part of an array, something gets lost in the middle of everything above... my selected piece is no longer the one that moves. when you click on the pathselector, the last piece in the array is the one that moves to it. so i suppose 'isSelected' isn't doing anything. any suggestions? i can provide more detailed scripts if that helps.
What would help is a bit of explanation around the concepts of your code. What is a piece? What is the path selector? What array is it you're speaking of? What has the "someTag" tag? What are you trying to accomplish? How does that differ from what's currently happening? Etc.
Totally yeah. Sorry, late night. This is for a board game. Four pieces per player. When you roll the dice you have to select re piece you want to move, then select the location on the path you'd like to move to (the path branches off with shortcuts). I have an array of player pieces, and I can get them to move along a path by just tapping a piece. When I add in the logic to have the piece wait until I choose a path for it to move to the selected path (shortcut or general) all hell breaks loose (the piece I selected no longer is 'selected' and ins$$anonymous$$d the last piece in the array moves.