Showing posts with label ipad. Show all posts
Showing posts with label ipad. Show all posts

Friday, September 17, 2010

Touchy Success


Finally the touch input is working. I thought I would be able to "talk" directly to a method on a game object from another class e.g. objectname.method. I have now realised that I needed to use the method getComponent() to access the methods of the objects. This has taken forever to realise. But now the code works! It needs refining but it works.


When I touch the screen a ray is sent along the z-axis into the 3d space (world space I guess). Whatever the ray collides with is "registered" in the raycast method's collider. Assuming the object the the ray collides with is an Kid object I can then access the methods in the kid and change it's state.

Wednesday, September 8, 2010

Det sku' vær så godt, men ...

I though it would be easy, but no. A week into the project I am learning that the stuff that looks like it's going to be hard making is medium difficult, whereas the stuff that appears super easy turns out to be hard.
After getting input from Martin and Steven (again thank you) I decided that I should rewrite all the code I've written so far. So instead of doing that I'd make a small easy thing, adding my own icon on the iPad for the game instead of the standard Unity icon.
An easy satisfying task. Unity Iphone even has a field for this under edit->project settings->player:


So I just drop and drag a 72x72 image on this field - a nice easy task; then build. Well no, this does not work! To the internet! After hours of reading forum posts, changing and testing I had no progress. Then I lost the Unity symbol and I was left with this:


A blank icon. Desperate and ready to write to David Helgason to apologise for losing their icon, I was ready to give up.
Most of the forum post I've read on the topic of icons and Unity iPhone mention that one would have to add the icon to the Xcode folder. Something I have been trying in different ways without luck.  Finally, Christoffer helped me and by magic he got it working without knowing how come it worked. So I backtracked everything.

Here's the solution:
Forget the icon field in Unity Iphone. It does absolutely nothing, apparently. What works is adding the 72x72 .png icon (if you are as I working on something for the ipad) to the Xcode folder. To work the image has to be named Icon-72.png or Icon-iPad.png (the file names are the real magic Ü).


So finally this is what I got after hours of desperate experimenting, yaaaaaay:

We have touch down

After a lengthy process that most fittingly can be described as black magic I now have Unity Iphone and a iphone developer licence installed on the computer. Thanks for your help Christoffer.

I did some small changes in the code and now the prototype is on the ipad. "Only" problem is code registers touches in general on the screen and the specific location of the touch as you can see in the video.


To interact by touch instead of mouse click I changed this
void OnMouseDown()
{
gameObject.tag="smile";
  SetCryTime();
}
to this
foreach (iPhoneTouch touch in iPhoneInput.touches)
{
if(touch.phase == iPhoneTouchPhase.Began)
{
gameObject.tag="smile";
SetCryTime();
}
}
and placed the code snippet inside the update function instead of outside. Next up is fixing the touch code so it only works on the object that are actually touched.