News: Enjoy our Christmas offer 30% off on our latest package Tower Defense Level Kit http://u3d.as/m7h

  • October 18, 2018, 03:11:18 AM

Login with username, password and session length

Author Topic: Multiple gesture scripts all triggering at the same time - help!!!  (Read 24 times)

Offline cstobler

  • Newbie
  • *
  • Posts: 1
Hi,

I don't know if this question has been asked before or not, I wasn't sure how to search for this issue, but I will describe it as best as I can.

We are creating a Myst-style first-person adventure game. Our scenes are setup in Unity 2D, with each pre-rendered background as a rectangular sprite, with a separate camera facing each one. I am trying to implement EasyTouch into it so that mobile players can swipe left or right to switch cameras (using separate asset for camera transitions; it is working fine). Each background sprite has a 2D box collider so it can detect the swipes.

My issue is that when I attach my swipe script to a background, for whatever reason, it will detect a swipe whether my mouse is over that collider/background or not. The result is that it will trigger 5 times if I have 5 backgrounds in my scene, even if I am only looking at one of them through the game view.

What am I doing wrong? How do I set this so that it will only trigger when my mouse is over the current background?

Let me know if I need to provide more info. I will include my gesture script below in case that will help (as you will see below, I tried .IsOverGUI to see if that would work. It did not.):

Code: [Select]
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using CameraTransitions;
using HedgehogTeam.EasyTouch;

public class NavScriptTest : MonoBehaviour {

    public Camera camOrig;
    public Camera camLeft;
    public Camera camRight;
    public CameraTransition cameraTransition;
    public float transSpeed;

    private void OnEnable()
    {
        if (cameraTransition == null)
        {
            cameraTransition = GameObject.FindObjectOfType<CameraTransition>();
        }
    }

    // Update is called once per frame
    void Update () {

        // Get current gesture
        Gesture currentGesture = EasyTouch.current;

        if (currentGesture.type == EasyTouch.EvtType.On_SwipeEnd)
        {
            //if (currentGesture.isOverGui)
           //{
                if (currentGesture.swipe == EasyTouch.SwipeDirection.Left)
                {
                    Debug.LogWarning("Left Swipe Successful!");
                    cameraTransition.DoTransition(CameraTransitionEffects.SmoothLine, camOrig, camRight, transSpeed,
                                      new object[] { 90.0f, 0.1f });
                }
                else if (currentGesture.swipe == EasyTouch.SwipeDirection.Right)
                {
                    Debug.LogWarning("Right Swipe Successful!");
                    cameraTransition.DoTransition(CameraTransitionEffects.SmoothLine, camOrig, camLeft, transSpeed,
                                  new object[] { 90.0f, 0.1f });
                }
            //}
        }
    }
}

Thanks,

Charlie


There are no comments for this topic. Do you want to be the first?