- Home /
Change Player object at touch
Hello and good day to all !
First of all, I want to apologize if I ask something that is stupid or for any other reason it is not right.
I am at the beginning of Unity development and I have a player, represented by a cube and a "+" button that adds other cubes. For the player game object I have attached a script that moves and rotates the player.
What I want to do is press any other newly generated cubes and have the selected cube to be the player and move that cube.
Is there any way of doing this ?
Thanks in advance. Dan.
Answer by dimitroff · Feb 25, 2014 at 06:08 PM
You could make the Player object just an empty GameObject and attach the control component on it, the component would have a variable which will be the currently selected cube, so your control component will control the cube, not the game object it's attached to.
That same component could also contains the logic for your cube selectio. If you are using the mouse for select, you could use Unity's Raycasts to find the object the mouse is currently on, there are tons of examples around the net how to do this.
Kamen