Here’s the summary: make sure you type all your vars, or you’ll get unexpected results.
Think Pong on the iPhone, with a finger to slide the paddle back and forth. Worked great. Then suddenly, touching the paddle caused it to slide to the right and off the screen. At first I thought that somehow force was being added in the loop, but nothing had changed. I’d added some new sprites with Sprite Manager 2, and thought I’d screwed that up somehow. Nope. Lots of head scratching, until I found that this code, which worked just fine before, in Unity iPhone 1.7:
var previousX : float = 0;
var mx = Input.mousePosition.x;
if (previousX == 0) {
previousX = mx;
}
else{
var deltaM = mx - previousX;
snip
}
was now (under Unity 3) returning deltaM of 0.5, even if the mx input point did not change.
This fixed it:
var previousX : float = 0;
var mx : float;
mx = Input.mousePosition.x;
if (previousX == 0) {
previousX = mx;
}
else{
var deltaM = mx - previousX;
snip
}
Yes: I know that JS is famously flakey about that kind of thing, especially with iPhone, but I’m posting this because it’s not obvious, and it might give others an idea about where to look if U3 seems to be behaving weirdly with previously good code.
And besides, (as a newb) it’s my first non- question post-back: I finally get to contribute! ![]()