Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Earth-O-Matic · Apr 19, 2011 at 06:38 AM · raycastiphonetimeclicktimescale

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.

Comment
Add comment · Show 4
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Earth-O-Matic · Apr 19, 2011 at 06:43 AM 0
Share

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...

avatar image Joshua · Apr 19, 2011 at 06:56 AM 0
Share

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?

avatar image Earth-O-Matic · Apr 19, 2011 at 07:09 AM 0
Share

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.

avatar image Earth-O-Matic · Apr 19, 2011 at 07:14 AM 0
Share

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

3 Replies

· Add your reply
  • Sort: 
avatar image
0
Best Answer

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!

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

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.

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Earth-O-Matic · Apr 19, 2011 at 07:29 AM 0
Share

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

avatar image Earth-O-Matic · Apr 19, 2011 at 07:30 AM 0
Share

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.

avatar image
0

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.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

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

Answers Answers and Comments

No one has followed this question yet.

Related Questions

Can i ignore timescale when playing AudioSource.PlayClipAtPoint ? 1 Answer

how to get smooth slow motion? 4 Answers

Lowering Time.timeScale and lowering Time.fixedDeltaTime 1 Answer

unity touch is not working properly 1 Answer

how to stop object before GO writes 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges