- Home /
Clicking on one object to destroy a specific number of tagged objects dragged sidebyside
Hello, i'm very new in gameDev. Concept: Only when 3 objects of the same tags(of which we have 2) are dragged next to one another can clicking on one of the Container on top of the platform add score and destroys them. How do I go about it? Your help would be much appreciated
[1]: /storage/temp/167669-2020-09-17.png
Answer by N-8-D-e-v · Sep 17, 2020 at 09:00 PM
something like this is what you need to detect if objects are next to each other. As for destroying objects when something is clicked, add something like this to the object you want clicked
GameObject[] objects;
string yourTag;
bool objectsNextToEachOther; //set this from another script
void Awake()
{
objects = GameObject.FindGameObjectsWithTag(yourTag);
}
void OnMouseDown() //monobehaviour method that senses if an object is clicked
{
if (objectsNextToEachOther)
{
foreach (GameObject obj in objects)
{
Destroy(obj);
}
}
}
Your answer
Follow this Question
Related Questions
Drag and drop on object to bounce back to it place unity c# 1 Answer
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
How to add a score when the correct object drags to the correct box? 1 Answer
How to create a Drag & Drop system which verifies what gameObject was dragged into the slot? 0 Answers