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 psyhova · Nov 06, 2014 at 04:00 PM · touchdooropenclose

Why is my door opening and closing at the same time?????????

Im not able to open the door and then close it by touch. My script opens the door and closes it immediately. It does not regonize if the boolean is true or not. it plays the animation at the same time. I want to touch the door then it should open. By the second touch it should close.

I tried a lot but no chance to fix it. The script is attachet to a door!!!

heres my script.//////////////////////////////////////////////////

private var focusObj:GameObject=null; // null Bedeutet das es leer ist

var dorop:boolean= false;

function Update ()

{

if(Input.touchCount>0&&Input.GetTouch(0).phase==TouchPhase.Began) // checkt ab ob der finger ber¸hrt

{

     focusObj = null;        // null Bedeutet das es leer ist

     var ray =Camera.main.ScreenPointToRay(Input.GetTouch(0).position);

     var hit : RaycastHit; 


                 if(Physics.Raycast(ray,hit,100000) && hit.transform.tag == "door" && dorop == false)
                 {
                 animation.Play("DoorOpenVorrat");
                 dorop=true;
                 print ("dorop=true");
                 
                 focusObj = hit.transform.gameObject;        // der Var focusObj wird das GameObjekt zugewiesen.
                 }
                 
                 if(Physics.Raycast(ray,hit,100000) && hit.transform.tag == "door" && dorop == true)
                 
                 {
                 animation.Play("Door CloseVorrat");
                 dorop=false;
                 print ("dorop=false");
                 }                
                 
 }


 if (focusObj&&Input.touchCount<0&&Input.GetTouch(0).phase == TouchPhase.Ended) // checkt ab ob der finger noch da ist

 {
 focusObj=null;
 }

}

So why it does not work????? Please can help me someone?????

Comment
Add comment
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

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by joni.giuro · Nov 06, 2014 at 04:07 PM

I think it's because on the first frame you touch the door and start the animation and set the dorop to true, then immediately comes the second frame and you probably still have the finger on the door (unless you're really, really fast) and this time the dorop variable is true so the door immediately closes. You should set dorop to true only when the animtion is complete.

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 psyhova · Nov 06, 2014 at 08:02 PM 0
Share

But how to accomplish??

yield WaitForSeconds(animation.clip.lenght);

does not work......

avatar image timdan · Nov 06, 2014 at 08:14 PM 0
Share

Try creating a faction that sets the variable "dorop" to true, and then call that function in that last key frame of the animation ins$$anonymous$$d of on the touch.

avatar image
0

Answer by psyhova · Nov 06, 2014 at 10:31 PM

Thank you guys I got it with coroutines.

Thanks

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Simple Script - and no result 2 Answers

How to make 2 doors with 2 diffrent keys 2 Answers

Open door without using tag 1 Answer

Door opens, plays sound, but can't close it. 2 Answers

Opening, Closing, Keeping door open at proximity 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