- Home /
Time not slowing down on iPhone
This works just fine in unity player and worked on iphone when I was calling the script from a GUI button instead of an object you click so I'm at a loss. But what I'm trying to do is stop time to allow the player time to place an object that spawns. Once the object is placed time speeds back up (on a separate script) it also works about 25% of the time as it stands now. here is the code...
function Update(){
var hit: RaycastHit; var ray = Camera.main.ScreenPointToRay (Input.mousePosition);
if (Input.GetMouseButtonDown (0))
{
if (Physics.Raycast (ray, hit, 300))
{
if(hit.collider.gameObject.tag == "ButtonDirection")
{
Instantiate(UIObject, SpawnObjectPoint, Quaternion.identity);
(findObject.GetComponent(ClickSpawn) as ClickSpawn).enabled = false;
Time.timeScale = .0000001;
}
}
}
}
It only works about 25% of the time when I click the object so it does work. I'm not sure what's happening.
I have a thought. On the other script I have after a touch phase has ended I have time speed back up. $$anonymous$$aybe there is an issue with the touch phase ending from clicking the slow down time object...
It sounds like that might be it. Remember that functions from OnGUI are called twice a frame + every event. Also, why are you not simply setting time to 0.0?
I had some issues a while back in the project with setting time to 0. .000001 gets the job done well enough for me. Pulling things from update are once a frame correct? Could be part of it. $$anonymous$$aybe I could do a LateUpdate? Still new to this code stuff so I could be wrong there.
Answer by Earth-O-Matic · Apr 20, 2011 at 07:54 AM
Fixed. I went a little different rout but I think it ends up working best on iPhone. Basically I was listening for a touch on two different pieces of code (the button and the object it drops) at the same time. This was causing a conflict. So I got rid of the if statement looking for a touch on the object and basically turned the object creation step into one move.
Now instead of pressing the button, spawning the object in the center of the screen, then clicking the object and doping it in place. I have you click and drag from the button as if you are pulling the object out of the button. Code is basically the same just with the second if statement looking for a button press gone and instantiating the object from the ray cast hit point instead of the designated Vector 3 position.
Actually end sup feeling pretty slick. Thanks for the replies guys!
Answer by karl_ · Apr 19, 2011 at 07:20 AM
How big is your button? I had a similar issue and the problem was that I was not able to hit the button consistently with touch input. Check this by putting a debug log in your if(hit) statement.
It's not an issue of pressing the button. This is the strange part because the button also spawns an object and it spawns the object every time. It just slows down time about 25% of the time but it creates the object 100% of the time. Like it's simply deciding to not slow down time every now and then
Only thing I can think of is the clicks for the first and second script are conflicting but the second script isn't even active until the object spawns.
Answer by Earth-O-Matic · Apr 19, 2011 at 07:20 AM
Posting the other script here that takes place after the time slow...
function Update () { var hit : RaycastHit; var ray = Camera.main.ScreenPointToRay (Input.mousePosition); for(touch in iPhoneInput.touches) {
if (Physics.Raycast (ray, hit, 100)) {
if(touch.phase == iPhoneTouchPhase.Moved && touch.phase == iPhoneTouchPhase.Began){
transform.position = Camera.main.ScreenToWorldPoint(Vector3 (touch.position.x, touch.position.y, 10));
}
if (touch.phase != iPhoneTouchPhase.Ended && touch.phase != iPhoneTouchPhase.Canceled){
var pos: Transform = Ptrans;
var create = Instantiate(CopyThis, pos.position, pos.rotation);
Destroy (hurtNow);
(clickItem.GetComponent(ClickSpawn) as ClickSpawn).enabled = true;
Time.timeScale = 1;
}
}
} }
Basically saying if the touch phase ends. To put time back to normal and place the drop object.