Hello Guys,
I need your help. First a little pice of my code (my question is at the bottom of the code):
...
for (var i = 0; i < Input.touchCount; ++i) {
var ray = Camera.main.ScreenPointToRay(Input.GetTouch(i).position);
var hit : RaycastHit; // Thats the variable i want to clear at the end of the code
if(Input.GetTouch(i).phase == TouchPhase.Began) {
if (Physics.Raycast(ray, hit)) {
if (hit.collider.gameObject == Button_Show_Help) {
Button_Show_Help.renderer.material.color = Color.green;
}
}
}
else if(Input.GetTouch(i).phase == TouchPhase.Ended) {
if (Physics.Raycast(ray, hit)) {
if (hit.collider.gameObject == Button_Show_Help) {
Button_Show_Help.renderer.material.color = Color.white;
}
}
The whole touch-code works like it should(above is just a litte pice of it) Thats not the problem. AFTER TouchPhase.Ended I want to clear the "hit.collider.gameObject" (which stores the touched object name). I already tryed this:
hit.collider.gameObject = null;
or
hit = null;
or
var hit_empty : RaycastHit;
hit = hit_empty;
But all this didnt work :( how can I clear this hit raycasthit variable
}
Looks like it's being declared as a local, first thing in the loop (but then I don't use Javascript much.) The question is missing a part. If he does another raycast, hit will be for that new one. If he doesn't do another raycast, why is he even checking hit?
– Owen-ReynoldsIndeed, exactly what I was thinking
– anon85704231Thank you Mike for the explination! I found the solution for my problem after understanding the raycasthit struct :)
– anon44451836