Answer by HarshadK · Apr 11, 2016 at 02:58 PM
A simple, non-optimized psuedo-Code for calculating the width and height of swipe gesture will be:
Vector2 startPos;
void Update()
{
if(touchPhase is start for your touch)
{
startPos = current position of touch;
} else if(touchPhase is end for your touch)
{
// This delta variable stores the width and height of touch
Vector2 delta = Mathf.Abs(currentTouchPos - startPos);
}
}
That measures the distance from A to B, but I need to account for any shape, say the width of a circle.
Also getting "cannot convert Vector2 to float" error to this:
Vector2 startPos;
void Update() {
if (Input.Get$$anonymous$$ouseButtonDown(0))
{
startPos = new Vector2 (Input.mousePosition.x, Input.mousePosition.y);
}
else if (Input.Get$$anonymous$$ouseButtonUp(0))
{
Vector2 delta = $$anonymous$$athf.Abs((new Vector2 (Input.mousePosition.x, Input.mousePosition.y)) - (startPos));
}
}
I also tried to get $$anonymous$$imum value for my mousePosition, but it keeps showing current one...
using System.Linq;
float [] $$anonymous$$imum= {Input.mousePosition.x};
Debug.Log ($$anonymous$$imum.$$anonymous$$in());
Any ideas?
For the Vector2 to float error, you actually have to pass x and y separately to $$anonymous$$athf.Abs since it takes a float. So delta line will become:
Vector2 delta = new Vector2 ($$anonymous$$athf.Abs(Input.mousePosition.x - startPos.x), $$anonymous$$athf.Abs(Input.mousePosition.y - startPos.y));
For the second part, can you explain what you are trying to achieve there?
Thank you, never ceases to amaze how noobish I am. It does only show Start and End distance however. Answered my own question with that 2nd method:
using System.Linq;
private List<float> posx1 = new List<float>();
private List<float> posx2 = new List<float>();
void Update(){
if (Input.Get$$anonymous$$ouseButton(0)){
posx1.Add(Input.mousePosition.x);
posx2.Add(Input.mousePosition.x);
}
if (Input.Get$$anonymous$$ouseButtonUp(0)){
Debug.Log (posx1.$$anonymous$$in());
Debug.Log (posx2.$$anonymous$$ax());
}
}
And voila, you have x bounds of gesture, repeat for y.
Your answer
Follow this Question
Related Questions
TextureParameter, get width? 0 Answers
How to find width and height of an gameobject with no renderer? 2 Answers
Canvas match width or height 1 Answer
How to get 2d camera width & height? 2 Answers
Find the Terrain Width and Height 1 Answer