- Home /
Script when tapping an object
I am trying to create a mobile app (Android).
①: Tap the object "Cube 1" ②: When you do ①, the object "Cube 2" is displayed. ("Cube 1" will be hidden)
What kind of script should I make when implementing the above behavior?
Answer by goutham12 · Oct 10, 2017 at 09:18 AM
can you clarify a bit more like
if cube1 clicked ----->cube1 will go to hidden and cube 2 will display up to here fine.
what if he taps on cube2 is there any other functionality.
if yes , then
bool click;
publick GameObject cube1,cube2;
if (Input.GetMouseButtonDown (0)) {
Ray ray = Camera. main. ScreenPointToRay(Input. mousePosition);
RaycastHit hit;
if(Physics. Raycast (ray, out hit))
{
if(hit. transform. gameobject.tag == "your cube's tag")
{
click = !click;
if(click){
cube1.setactive(false);
cube1.setactive(true);
}else{
cube1.setactive(true);
cube2.setactive(false);
}
}
}
if no then
do the above only when click true
Answer by lernoh · Oct 10, 2017 at 11:32 AM
Oh that is interesting for me too. But I am going to use that in online multiplayer via browser. Can I use this script ? and on which object should I put this script? To create an empty and tag as a player? or game manager ?
For multiplayer this code doesn't work. can you explain me a bit brief that what you exactly needed.
I need to create a 2d simple game in 3d space. All is needed to do is to choose one of 3 boxes. and if some of boxes choosen it becomes inactive for other online players who are playing via browser. And after they have already made their choise the system randomly chooses one of that 3boxes. So now I have made all the objects but I need some script which will allow the players to choose their boxes. If any ideas concerning to this please please tell me. or give me some hint. any simple word can be useful. Thanks. :) !!!!
first for multiplayer game the above code works 0%
let me know which network your are using for multiplayer game. i mean photon or unity network.
I don't even know what's the differencebetween them , but i use unity network.