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 Exagerate · Mar 10, 2013 at 10:49 AM · c#itweendoorstween

iTween with bool C# issues

Hi there, i'm currently trying to get a door that when you hit the '2' on your keyboard, it opens/closes. It also plays a different sound for each. I believe my problem to be with file structure, originally I had it working simply but the tween could be interrupted if the key was hit again and it would then begin moving the opposite direction, as one would expect. So I played around a little and I came up with the code below to attempt to lock it from moving while in motion, however, my issue is: • If you hit the key while it is in motion, it doesn't interupt, but it does alternate the bool so that when it's hit when it isn't moving, it will go a different direction, thus causing the same issue as before. • Being a double door, one slides one way, the other slides another way, I applied a second code with the filename passdoorback and with a -0.7 tween where it was 0.7 on the front door, which works fine but it only works once, it seems like it is convinced that it's not finished moving when it actually has, yet the file is identical to the forward moving doors. With some testing, removing the "isMoving = true;" from this second script fixes it, but of course I don't want it to move interrupted while it's in motion...

Any insight would be appreciated, my knowledge of C# isn't fantastic but it's progressing.

 using UnityEngine;
 using System.Collections;
 
     public class passdoorfront : MonoBehaviour
 {
     
     public AudioClip DoorOpen;
     public AudioClip DoorClose;
     
     bool b = true;
     bool isMoving = false;
 
     private Vector3 v3To;
 
     void Update () {
         
     if(Input.GetKeyDown(KeyCode.Alpha2))
         
     {
        SetOpenClose (b);
        b = !b;
     }
     }
     
     void SetOpenClose(bool bOpen) {
 if (!isMoving) {
 
 isMoving = true;
 
         if (bOpen) {
        iTween.MoveBy(gameObject, iTween.Hash("z", 0.7, "easeType", "easeInOutExpo", "delay", 0.5, "Speed", 0.15, "onComplete", "toggleDoor"));
         audio.PlayOneShot(DoorOpen);
         }
        else {
        iTween.MoveBy(gameObject, iTween.Hash("z", -0.7, "easeType", "easeInOutExpo", "delay", 0.8, "Speed", 0.15, "onComplete", "toggleDoor"));
         audio.PlayOneShot(DoorClose);
         }
 }
     }
 
 void toggleDoor() {
 
 isMoving = false;
 
 
 }
 }
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

0 Replies

· Add your reply
  • Sort: 

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

10 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 Answers

iTween input with spring 1 Answer

Itween Problem 0 Answers

Play iTween on instantiated prefab 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