hii,everybody, it may be simple basic question but really imp to understand.
i have created a prefab, also created custom tag for it. and attached '1' cube to it.
now i tried to written a simple raycast component related script to detect that cube after hit as follows.
if(Input.GetMouseButtonDown(0)) {
var ray : Ray = Camera.main.ScreenPointToRay (Input.mousePosition);
var mousehit : RaycastHit;
if (Physics.Raycast (ray, mousehit) && (mousehit.collider.tag == "try03")) // try03 is custom tag { mousehit.transform.gameObject.active = false;
Debug.Log(collider.tag.Length); }
}
now see that last line
Debug.Log(collider.tag.Length);
from this line i will get collider tag length, means if i am attached only one cube to prefab, means only
one tag is is there, and that Debug function line should give me value equal to '1'. but it is giving me
value 5 why?
Am i rit ? or this gives another value?
Any help will be helpful.
Thanks,
ohh.. thanks. is there any other method to count , that how many cubes i u have hitted or clicked. Means if there r 2 cubes in my scene, above script i can apply to it. but how should i will know that how many cubes are clicked ?
– anon62947158so is there any way to use raycast, or something else to count how many cubes u have been hitted.?
– anon62947158I have changed the code to show you how to keep track of the number of cubes that have been hit.
– Meltdownyes ur logic is absolutly correct. i was also tried in this way. But i am getting one problem here. suppose i have taken 2 cubes in scene, and when i'm hitting 2 cubes after one another, i'm getting only one return value , i should need to get return value '2' using Debug.Log(numCubesHit). I think this is the main problem, that why i am not able to move to next level. Why is it so?
– anon62947158Where is your script attached to? Don't attach the script to the cube. Create an empty GameObject called GameManager. And attach your script to that. Then it should count correctly. Le tme knowif that works.
– Meltdown