The problem is when I write my ray cast and the list of tags to check it becomes too long, 2 are ok, but when I add search, speak, attack etc, its way too long, because I have to also add the same hit.collider.gameObject.tag code.
if(Physics.Raycast(ray,out hit, reachDistance) && hit.collider.gameObject.tag == "Pickup" || hit.collider.gameObject.tag == "Touch" || hit.collider.gameObject.tag == "Door") {
if (hit.collider.gameObject.tag == "Pickup")hand = 1;
if (hit.collider.gameObject.tag == "Touch") hand = 2;
if (hit.collider.gameObject.tag == "Door") hand = 3;
}
else hand = 0;
I was thinking of creating a list of if statements but worried about fps loss on each update like;
handTags = new string[] {"Pickup","Touch","Door","Search","Open","Talk"};
Is there another way instead of the list? I would of use the switch case, but I believe it only uses numbers I tried as a test;
case : if(Physics.Raycast(ray,out hit, reachDistance) && hit.collider.gameObject.tag == "Pickup"):
hand = 1;
break;
I would of great great then I would had;
default:
hand = 0;
break;
This way when the ray did not touch any of these tags hand will return to 0 and remove the hand cymbol at the center of the screen.
Currently everything works, just looking for more efficient way, for when I add more tags.