Onmouseclick on Cube a sphere should be created inside the cube and On second click it shouldn't
hi, I am a beginner, There are 3 cubes which are created using Prefabs. I am trying to create a sphere on clicking on cube 1 a sphere should be created. On the second click it should not create sphere. On clicking on the cube 2 it should create a sphere ,on second click it shouldn't and vice versa. I want it to be done in Dictionary key value. What i have to do now?
Thanks.
Answer by hexagonius · Feb 16, 2016 at 08:49 PM
I guess you want to have the dictionary match the cubes with the spheres. Usually you do this via raycast, but I think those OnMouse functions are called when placed in a script on a gameobject, right? so create that script with a static dictionary in it. before spawning check the dictionary for the current cube. Add it and the spawned sphere if not. since the dictionary is static every instance of that script put on a cube can just access it and see if it exists already
Thanks for your valuable reply. Ya I can use static dictionary but the think is cube are prefabs which are created only at runtime so i want to store the cube name in key and sphere in value.
Your answer
Follow this Question
Related Questions
Instantiate PreFab on trigger location 0 Answers
How to make prefab clones selectable? 0 Answers
How can I detect prefabs edited in the prefab editor in OnValidate? 2 Answers
Working with UI as prefab, will change values outside the prefab 0 Answers
The Unity version determines the hierarchical order of the Scenes 0 Answers