x


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.

more ▼

asked Apr 19 '11 at 06:38 AM

Earth-O-Matic gravatar image

Earth-O-Matic
70 9 9 18

I have a thought. On the other script I have after a touch phase has ended I have time speed back up. Maybe there is an issue with the touch phase ending from clicking the slow down time object...

Apr 19 '11 at 06:43 AM Earth-O-Matic

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?

Apr 19 '11 at 06:56 AM Joshua

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. Maybe I could do a LateUpdate? Still new to this code stuff so I could be wrong there.

Apr 19 '11 at 07:09 AM Earth-O-Matic

Naw that's stupid. It's late. Trying other stuff.

Apr 19 '11 at 07:14 AM Earth-O-Matic
(comments are locked)
10|3000 characters needed characters left

3 answers: sort voted first

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!

more ▼

answered Apr 20 '11 at 07:54 AM

Earth-O-Matic gravatar image

Earth-O-Matic
70 9 9 18

(comments are locked)
10|3000 characters needed characters left

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.

more ▼

answered Apr 19 '11 at 07:20 AM

karl_ gravatar image

karl_
2.4k 41 53 69

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

Apr 19 '11 at 07:29 AM Earth-O-Matic

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.

Apr 19 '11 at 07:30 AM Earth-O-Matic
(comments are locked)
10|3000 characters needed characters left

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.

more ▼

answered Apr 19 '11 at 07:20 AM

Earth-O-Matic gravatar image

Earth-O-Matic
70 9 9 18

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x1998
x1525
x570
x225
x83

asked: Apr 19 '11 at 06:38 AM

Seen: 738 times

Last Updated: Apr 19 '11 at 06:38 AM