-1

context to the problem: I've got multiple sorts of cubes set up, placed in an array. I've made it so every different cube has his own parent, so all the cubes are grouped together with the other cubes of the same type.

I'm trying to move all the cubes of the same type up in the air away from the others so it becomes more visible how many cubes of the same type there are. my thought was that when any of the child objects get clicked, all of the objects under that parent move; but so far no succes.

Anyone got any tips as to how this might be able to work?

Note that I don't intend to use raycast as it seems overly compicated for this purpose.

Sten Martens
  • 61
  • 1
  • 6
  • Are you trying to find a solution to detect a mouse click on a cube or a solution to move child object along with a parent? Because I don't see why you're talking about raycasting when your question is about moving objects... Could you be a bit more precise? – MadStark Sep 25 '17 at 08:12
  • @lockstock write down an answer just before mine, my answer was pretty similar to it so i've delete my post. – Thalthanas Sep 25 '17 at 08:20

1 Answers1

4

If your cubes have colliders you can use OnMouseDown, in a script attached to each cube:

void OnMouseDown()
{
    transform.parent.transform.Translate(Vector3.up * WhateverDistance);
}

If your cubes dont have colliders you'll have to use raycast to detect which cube has been clicked

lockstock
  • 2,359
  • 3
  • 23
  • 39