dirtrider478 12 Share Posted December 28, 2020 Im working on a script and am wondering if once a gameobject is found and clicked on is there a way to check if that specific gameobject I just clicked on is still there. Link to comment Share on other sites More sharing options...
SubCZ 283 Share Posted December 28, 2020 //Get object and its unique index GameObject obj = GameObjects.closest(objId); int objIndex = obj.getIndex(); ... //Check if obj is gone boolean objGone = GameObjects.closest(obj -> obj != null && obj.getID() == objId && obj.getIndex() == objIndex) == null; This is what I do if there's multiple game objects of the same type around. If it's the only one in the vicinity you can just leave out the index part Link to comment Share on other sites More sharing options...
Pandemic 2798 Share Posted December 28, 2020 20 minutes ago, SubCZ said: //Get object and its unique index GameObject obj = GameObjects.closest(objId); int objIndex = obj.getIndex(); ... //Check if obj is gone boolean objGone = GameObjects.closest(obj -> obj != null && obj.getID() == objId && obj.getIndex() == objIndex) == null; This is what I do if there's multiple game objects of the same type around. If it's the only one in the vicinity you can just leave out the index part You could also use GameObject#exists: GameObject obj = GameObjects.closest("Whatever"); // Later on... if (obj.exists()) { // Object still exists } else { // Object doesn't exist } Link to comment Share on other sites More sharing options...
dirtrider478 12 Author Share Posted December 28, 2020 Thanks guys ill try these out. Link to comment Share on other sites More sharing options...
abouhanafy87 4 Share Posted June 11, 2021 On 12/28/2020 at 9:24 PM, Pandemic said: You could also use GameObject#exists: GameObject obj = GameObjects.closest("Whatever"); // Later on... if (obj.exists()) { // Object still exists } else { // Object doesn't exist } What about if there's multiple game objects of the same type around Link to comment Share on other sites More sharing options...
abouhanafy87 4 Share Posted June 11, 2021 There is 3 rocks i want to know when its exists and if i interacting one i can chech when its not exist but if other player interact another rock how can i know when it not exists Link to comment Share on other sites More sharing options...
abouhanafy87 4 Share Posted June 16, 2021 On 12/28/2020 at 9:24 PM, Pandemic said: You could also use GameObject#exists: GameObject obj = GameObjects.closest("Whatever"); // Later on... if (obj.exists()) { // Object still exists } else { // Object doesn't exist } @Pandemic What about multiple game objects of the same type around Link to comment Share on other sites More sharing options...
TheCloakdOne 389 Share Posted June 16, 2021 You could either get the rock based on its tile, or store each rock in a var each time you loop and check each var if it exists Link to comment Share on other sites More sharing options...
abouhanafy87 4 Share Posted July 9, 2021 On 6/16/2021 at 12:15 PM, TheCloakdOne said: You could either get the rock based on its tile, or store each rock in a var each time you loop and check each var if it exists How can I store rock in var ? Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.