-1

I have a 3D cube (game object with material) in my Unity 3D application (C# scripts). If the user clicks the cube, I want a small red circle drawn on the cube at the exact mouse position where the user clicked. The cube's position may change as it can move around the board, but the circle should stay on the cube, at the proper position, like a sticker placed on it. Another way to think of it, pretend it's a character and they just got shot. The bullet hole follows that character as they move around.

What is the best way to achieve this in Unity? Ideally, once drawn, I wouldn't have to continue to recalculate the circles position as the cube moved around (as I imagine that will prove difficult over time). I just want it stuck to the cube, again like a sticker.

Note: At any given moment, there would only be 20 or so of these circles, so performance isn't a huge concern.

Nullqwerty
  • 1,140
  • 1
  • 20
  • 37
  • 2
    Attach objects maybe? http://answers.unity3d.com/questions/58486/how-do-i-programatically-attach-objects-to-each-ot.html – Mokey Feb 09 '17 at 18:05
  • easy way, instantiate a gameobject at the clicks position, efficient way, draw the "bullet hole" on a sprite where the user clicked and keep modifying the sprite when ever the user clicks... But this isn't really a question for SO, because you're not showing what you tried and what didn't work. You should try things out and if it doesn't work, ask specifically about it. http://stackoverflow.com/help/how-to-ask – Alox Feb 09 '17 at 18:08
  • I'm new to Unity. The ideas that I've had all seem like a high level of effort (all involve manually moving the circles), which is why I was asking to see if there's an easy way to accomplish this in Unity. – Nullqwerty Feb 09 '17 at 18:32
  • @Mokey this might be exactly what I was looking for. It opens a few questions as to how I get the proper relative position, but I'll try it out and research that further. Thanks! – Nullqwerty Feb 09 '17 at 18:34
  • @Mokey works beautifully! Thanks for the suggestion. Gotta say...disagree with the down-votes of this question. Sometimes you don't know what you don't know. – Nullqwerty Feb 09 '17 at 18:41
  • 1
    @Nullqwerty This is commonly called drawing a _decal_. Decal's are the 2D solution - that's where you get an image splatted flat on the surface of the 3D object. – Luke Briggs Feb 09 '17 at 18:53
  • Glad it works! Upvote the comment :) – Mokey Feb 09 '17 at 19:10

1 Answers1

0

As mentioned in the comments above, using the transform parent handled this perfectly, in only one line of code:

sphere.transform.parent = cube.transform;
Nullqwerty
  • 1,140
  • 1
  • 20
  • 37