Exemplo n.º 1
0
    //---------------------------------------------------
    // OnBecameInvisible()
    // Nifty callback function that will tell us when
    // the object is no longer being rendered by the
    // camera.
    //---------------------------------------------------
    void OnBecameInvisible()
    {
        NinjaTrigger triggerParent = transform.parent.gameObject.GetComponent <NinjaTrigger>();

        if (triggerParent)
        {
            triggerParent.ChildBecameInvis();
        }
        else
        {
            Debug.LogError("Trigger child does not have a parent...");
        }
    }
Exemplo n.º 2
0
    void OnDrag(DragGesture gesture)
    {
        if (!isPlaying)
        {
            return;
        }

        // update the ninja gesture cut trail
        UpdateTrail(gesture);

        // Figure out the direction of the trail
        Vector2 dir = gesture.TotalMove.normalized;         // you could also use Gesture.DeltaMove to get the movement change since last frame

        FingerGestures.SwipeDirection swipeDir = FingerGestures.GetSwipeDirection(dir);

        if (swipeDir != lastDirection &&
            swipeDir != FingerGestures.SwipeDirection.UpperLeftDiagonal &&
            swipeDir != FingerGestures.SwipeDirection.UpperRightDiagonal &&
            swipeDir != FingerGestures.SwipeDirection.LowerLeftDiagonal &&
            swipeDir != FingerGestures.SwipeDirection.LowerRightDiagonal)
        {
            AudioManager.Instance.PlayClip("ninjaWhoosh", variations: 3);
        }
        lastDirection = swipeDir;

        switch (gesture.Phase)
        {
        case ContinuousGesturePhase.Updated:
            GameObject go = gesture.Selection;
            if (go)
            {
                //Debug.Log("Touching " + go.name);
                NinjaTrigger trigger = go.GetComponent <NinjaTrigger>();

                // if the trigger is null, check the parent...a little hacky, but sue me!
                if (trigger == null)
                {
                    trigger = go.transform.parent.gameObject.GetComponent <NinjaTrigger>();
                }
                if (trigger)
                {
                    trigger.OnCut(gesture.Position);
                }
            }
            break;
        }
    }