First of all thanks for this amazing asset, just the bought the plus to support you
I stumbled upon some static actions in LeanTouch.cs, that JetBrains Rider (or Resharper) marks as dangerous:
public static System.Action<LeanFinger> OnFingerUp;
// several samples (e.g. LeanFingerHeld.cs) us in code like
LeanTouch.OnFingerUp -= OnFingerUp;
The -= for unsubscribing is marked with a hint Delegate subtraction has unpredictable result. You can find a detailed explanation at JetBrains help page.
I think OnFingerUp should be rather declared as an event e.g. public static event System.Action… so that listeners can safely subscribe and unsubscribe no matter how many listeners exist.
But maybe I am wrong and this is intended. In that case we should register/unregister our one and only listener by assignment like
LeanTouch.OnFingerUp = OnFingerUp;
// and unregister
LeanTouch.OnFingerUp = null;
I’ll consider changing them to events. I think this warning is silly in this scenario though, because -= OnFingerUp; is just unsubscribing a method, so there is no scenario where this will cause the behaviour described on that page. They should really improve their parsing skills to test to see if the user is adding multiple methods together like this before warning of this.
Hello i have a Question to LeanPool, i have a Terrain Map,on this map i have Place same Items(stone) the player can go to the stone and pick it the Stone up in him´s inventory.
My Idea is create 1 Empty Object und that i have the stones from the map,when player have 20 Stone´s pickit up the emptyObject will respawn the stone´s.My Question is can i do that with LeanPool,i have see LeanPool have one Object and respawn that on the same position,must i set up on every stone the LeanPoolScript or can i use a Array or list?
I’m not sure I fully understand your scenario. When using LeanPool it’s best to think about how you would normally design your game using Instantiate/Destroy with your prefabs, and you can just replace them with Spawn/Despawn. LeanPool doesn’t contain any code to count to 20 and do special logic, you would have to write a custom script to do that.
hello,
using Lean Transition, how can i create Ping pong effect with code only? (without adding lean component)
i managed to create UP and then Down but how do i make it repeat forever?
The easiest way is to call a method containing your transitions, then have the last transition call itself, like this:
using UnityEngine;
using Lean.Transition;
public class RepeatFromCode : MonoBehaviour
{
void Start()
{
UpAndDown();
}
void UpAndDown()
{
if (!isActiveAndEnabled) return;
transform.
localPositionTransition(Vector3.up, 1). // Move up
JoinDelayTransition(1). // Wait 1 second
localPositionTransition(Vector3.down, 1). // Move down
JoinDelayTransition(1). // Wait 1 second
EventTransition(UpAndDown, 0); // Begin again
}
}
In theory this could be done with less code using InvokeRepeating, but apparently there’s a bug somewhere that I must track down to allow that. I’ll look into it!
I checked your SwipeDirection8 demo. When I finger up that return direction value one time in demo. But I want to return direction values continuously until my finger up. How could I do this?
If you want it every frame then you could use LeanFingerDrag.OnFIngerDrag instead of LeanFingerSwipe.OnSwipe. Drags have no direction constraints though. If you want this then then LeanTouch+ has the LeanFingerSwipeNoRelease component, which can do continuous swipes.
Hi, I use the LeanCameraMove and LeanCameraZoom (2D) from the demo, is it possible to limit the camera movement position based on maximum view I set, so the limit of camera’s position will depend on how far I zoomed out/zoomed in the camera? (hope you get what I mean)
There’s no feature to do this yet, but I added it to the to-do list. It may require a new component since it will likely work very differently to the current constraint/boundary components available in LeanTouch+.
I’m using this awesome and free LeanTouch asset for a little game I’m making and came across a small issue: I made a script that extends from LeanSelectable. In the Start method, it adds buttons to the ui. The problem is that these buttons also get added in the editor, and not only in play-mode. The second time, play-mode is started, there are 2 sets of buttons in the UI, etc.
This is because the LeanSelectable class has the attribute ExecuteInEditMode. Why does this class have this attribute?
There are also a few other classes with this attribute. Do they need this attribute as well?
This attribute probably isn’t necessary for any of the components. It’s used to register the component instances, and that data might be used by some other components in the editor, but it’s probably not important.
This is a partial rewrite of all example components, so please don’t update if you’re in the middle of a project!
This new version includes so many changes.
The biggest change is that I removed all __Smooth versions of components, and instead included the smoothing code in the basic version of each component. This simplifies how you use Lean Touch because there are now far less components, and it allows me to make changes much faster.
The second biggest change is that I added many more events to each finger and multi finger component (e.g. LeanFingerTap, LeanMultiSet). These new settings allow you to get the world position of fingers, world delta of fingers, etc. Implementing these settings in the finger components simplifies a lot of interaction with other components (e.g. manually adding Rigidbody velocity from finger gestures), and allows you to do many of the same things as before, but now using less components, thus being easier to understand.
Next up is the new FingerFilter inspector settings. These are used by components like LeanMultiTwist under the setting name of Use. This inspector setting simplifies a lot of component code, because all components that work with multiple fingers now use this same system.
Finally, I re-designed all the demo scenes and updated the description text to be clearer. There are many other small tweaks I made in Version 2.0.0, so I recommend you go through the scenes again, read the description, and understand what was changed.
If any of the new things look confusing and need more explanation or you need more demo scenes then feel free to post below!
Hi Darkcoder, I’m attempting to use LeanTouch+ for an AR game - it’s really helpful that translations (eg. LeanDragTranslate) work relative to camera angle since the AR camera can be positioned anywhere.
Currently LeanDragTranslate only moves an object on the X/Y axis but I need an option to move it on the X/Z axis instead. ie. when you move your finger up/down on the screen the object should move away/towards the camera. Can you describe how I might achieve this? Thanks!
This can be done using LeanTouch+ with the LeanDragTranslateAlong component. With this component the ScreenDepth setting can be set to HeightIntercept or PlaneIntercept, allowing you to move away/towards the camera based on a flat surface along the X/Z axis.
Well first of all this is an amazing Asset!
Im currently working on a mobile 2d endless runner with this functions:
-Touch on the left side of the screen = jump
-Touch on the rightside of the screen = attack
-Swipe down wherever on the screen = Quickly fall when in air or through platforms when obstacle ahead
My question is:
Where exactly do I have to implement the check to see on which side of the screen the player taps?
Want to add something like this:
if(touch.position.x < Screen.width/2){
tapL = true;
}else if(touch.position.x > Screen.width/2){
tapR = true;
}
Thanks for the reply! I’ve got PlaneIntercept setup to be constrained to a LeanPlane which works fine in most situations, however when the camera is looking straight down the edge of the plane, the’s no way for the system to understand where to move the object along the Z axis. So this isn’t going to work well for AR since the camera could be anywhere, including parallel to the plane.
Another issue with LeanDragTranslateAlong + LeanPlane is that after the object hits the Y plane extent if you keep pushing in the same direction the object will push over to the X extent even if I’m not moving my finger along the X axis. Instead the object should stay at the last X position at the Y extent until I actually move my finger along the X.
Would it be possible to have a variation of LeanDragTranslate with the option to move along the X/Z axis rather than the the current X/Y axis?
From code you would hook into the Lean.Touch.LeanTouch.OnFingerDown and OnFingerSwipe events. Both of these events give you a LeanFinger finger as an parameter. You can then read the finger.ScreenPosition value, and perform the code you describe.
If you use LeanTouch+ then you can make a UI rect covering the areas of the screen you want, and then add the LeanFingerDownCanvas component to it, which will call the OnFinger event when you begin touching over that UI element. However, it looks like you can’t detect swipes using this method yet. I’ll add it to the to-do list!
In this scenario you would need to use a setup like the FirstPersonLookMove demo scene, where the movement distance is based on the drag distance rather than anything in the scene. Components like LeanDragTranslate and its variants work using a scene reference point, and if your reference point is a plane then when viewed side-on there’s no valid reference point to translate using. For objects the same style of movement can be done using the DragMove2D demo as a base, but with a different DirectionB setting.
I have successfully used the swipe function to swipe down whenever i want. As for the OnFingerDown in order to jump…the character jumps immediately before the script manages to ckeck if it is a swipe.
To solve this I tried the OnFingerTap implementation but the problem here is that the character only jumps when taking the finger from the screen (makes the game feel laggy)! Is there a way to use OnFingerDown with the touchthreshold together? This would be the final solution for my project!!!