|
Hii, i am trying to create one memory game. In which i can click on number of prefabs(cubes) which are present there.Now i want to apply condition that, unless i'll click on certain number of cubes, i cant go to next scene. Eg: If we r having 3 cubes present on scene, and i need to click on 'two' correct one cubes.Now here how can i check that they are clicked on correct one? we can move to further scene if and if only when we confirmed that one has correctly clicked on two correct cubes. If my question seems incomplete, then also let me know , i'll try to explore it. Any help will be helpful.. Thnks,
(comments are locked)
|
|
well if you are asking for some especific prefabs, then you need to have 3 or n number of booleans, then in the update, on a foreach touch, make a raycast to the touch.position, then check if the raycast hit one of your designated prefabs, if so, turn a bool on, continue this proces for your n prefabs/touches, and if all your booleans are on, then make an Application.Load(scene) hope this is the answer you are looking for ok, i am trying on this way.. private var hit : RaycastHit; private var isTouchCube1:boolean=false; private var isTouchCube2:boolean=false; function Update () { if((hit.box_v001_2==clicked)&&(hit.box_v001_3==clicked)) { isTouchCube1=true; isTouchCube2=true; } if((isTouchCube1==1)&&(isTouchCube2==1)) { Application.LoadLevel ("level1"); } //here box_v001_2 & box_v001_2 are my cube http://names.my logic may be right,but i know am doing wrong thing here. wht should i have to do to correct this ...?
Mar 17 '11 at 09:00 AM
pravin gate
If i need to apply different login then also let me know.
Mar 17 '11 at 11:03 AM
pravin gate
i usually use this way on the raycast Ray ray = Camera.main.ScreenPointToRay(Input.mouseposition); RaycastHit hit; if(Physics.Raycast(ray, out hit)) { //this give me the transform i hitted - hit.transform.name then use it as you want like if(hit.transform.name == "box_v001_2") isTouchCube1 = true; if(hit.transform.name == "box_v001_3") isTouchCube2 = true; //then to acces your new level will be same as you have it, btw booleans inside an if doesnt need to be compared, just used like this if(isTouchCube1 && isTouchCube2) //this means if( (true) && (true) ) in this case //note that this is C
Mar 17 '11 at 02:39 PM
poncho
C# and you will need to use the comparative on js but is almost the same
Mar 17 '11 at 02:40 PM
poncho
(comments are locked)
|
|
ok no problem.... i got part of soln... in this way... function Update () { if ( Input.GetMouseButtonDown(0)) { var hit : RaycastHit; var ray : Ray = Camera.main.ScreenPointToRay (Input.mousePosition); if (Physics.Raycast (ray, hit, 100.0)) { Application.LoadLevel ("good_work_01"); } } } so now using raycasting i can go to nxt http://scene.so anybody plz tel me how can use this for checking 2 or n number of cubes. I mean to say when n number of cubes will be clicked, then only he can move to the next level so what should be the changes needed in this code....? Is there anybody to help me out? i'm really stucked with this problem from last 2 days...
Mar 18 '11 at 11:54 AM
pravin gate
According to above , why this is not working, what is the problem in this code? function Update () { if(Input.GetMouseButtonDown(0)) { var hit:RaycastHit; var ray = Camera.main.ScreenPointToRay (Input.mousePosition); if (Physics.Raycast (ray,hit,100.0)) { if(hit.transform.name=="box1") //here box1 is my prefab(cube) name { isTouchCube1=true; } if(hit.transform.name=="box2") //here box2 is my prefab(cube) name { isTouchCube2=true; } if(isTouchCube1 &&isTouchCube2) { Application.LoadLevel ("oops_01"); } } } } Any help will be useful.
Mar 18 '11 at 02:32 PM
pravin gate
Does anybody knows how to solve this problem?
Mar 21 '11 at 04:25 AM
pravin gate
Please do NOT flag posts as "Requires moderator attention" just because you want an answer...! Moderator attention is for taking action on posts that are inappropriate.
Mar 21 '11 at 12:34 PM
runevision ♦♦
(comments are locked)
|
