- Home /
iPad touch scripting...
Here is what I want to do. I'm trying to make a script, or scripts, that can help me do these things:
Detects the player as he touches the screen.
When the player has touched an area, which is right above the intended moving character prefab, it does four things at once.
-Adds points to score board.
-Changes the animation for the character.
-Plays the audio file component.
-Increases the speed of the character that was touched.
I have made a script, but its not working at all. What can I do to fix it? I've looked around and found several different ways to do the same thing but they don't work either. Its getting frustrating.
My current touch screen code:
void Update () {
foreach (Touch touch in Input.touches){
if (touch.phase == TouchPhase.Began){
Ray ray = Camera.main.ScreenPointToRay(touch.position);
RaycastHit hit;
if (Physics.Raycast(ray, out hit)){
hit.transform.SendMessage("Selected");
}
}
}
}
Raycasting only works on objects that have a collider of some kind. Otherwise there's nothing wrong with the script, or at least if I replace the touch stuff with mouse input (don't feel like hooking up my iPod touch at the moment), it works fine.
Your answer
Follow this Question
Related Questions
iPhone StoreKit implementation problem 2 Answers
From Unity to Xcode.... 1 Answer
Working with Touch screens... 1 Answer