- Home /
How to Detect Touch on a Random String from a List?
Hi.
I'm trying to detect when a specific random string is touched from a List.
I'm using HitTest to detect the touches, which works fine.
However, I'm stuck at trying to detect which specific string is touched.
Using a .tag to detect touch on the string would work, but you cannot tag (that I know of) strings that are in List.
Using index or element won't work because the strings are being pulled randomly, so they are always in a different order.
Any ideas on how to go about doing this?
Thanks in advance!
First off, you need to abstract the problem a bit further than 'trying to hit strings', because strings don't have colliders. :)
I assume that you must be instantiating some prefab that has a GUIText object (or something) and a collider, right? Because, otherwise, you'll just never see or hit anything.
If I'm way off base here, please correct me. Your setup is important and, without a little more information, it's really impossible to help you with your particular problem. The only thing left to do would be for someone to tell you how they'd implement what they interpret your problem to be.
I can hit the strings with HitTest, which works. It returns what string was touched in the Console. Thats fine, there's no problem there.
The problem is because the strings are placed in a random order, I have no way of detecting when the correct string is touched.
The closest I've come is this in the Update:
if(thisString.Contains("WhateverYouWant") && isTouching){
Which seems like it should work, but doesn't.
To make things even weirder it, it printed in the console once when I flipped isTouching to false, while testing. It did work, but only once.
Don't know, might have to rethink my approach on this one.
Answer by fafase · Jun 03, 2014 at 06:07 AM
"Using a .tag to detect touch on the string would work, but you cannot tag (that I know of) strings that are in List."
You can use a dictionary where the key would be your tag and the value would be your string.
Your answer
Follow this Question
Related Questions
Trouble displaying lists of strings in a text box 1 Answer
(c#) display a random string at game over 2 Answers
Random role assigning from string array 1 Answer
A node in a childnode? 1 Answer