- Home /
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;
}
}
Your answer
Follow this Question
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