Tag "mShape" is the yellow shapes.
Game Work When : * The ball will not create if you clicked over the yellow shape. * Click the red space will create a ball (PointA), When I moves my finger i see path of dots as direction (PointB), When i release my finger, Ball will move.
Game Not Work When : when i keep pressing with my finger over the yellow shape and drag with my finger the touch. I got the bug.
*I used "Log viewer" assets to detect the bug when i play in my device.
if (ShowDir)
{
pointB = Camera.main.ScreenToWorldPoint(Input.GetTouch(0).position);
pointB.z = Ball.transform.position.z;
if (DirDectect)
{
if (DottedLine.DottedLine.angle < 92 && DottedLine.DottedLine.angle > 88)
{
AudioSource my_audio = GameObject.Find("SDir").GetComponent<AudioSource>();
my_audio.Play();
pointA.Set(MyBall.GetComponent<Transform>().position.x, pointA.y, pointA.z);
pointB.Set(MyBall.GetComponent<Transform>().position.x, pointB.y, pointB.z);
//DirDectect = false;
Invoke("DirDet", 0.7f);
}
if (DottedLine.DottedLine.angle < 272 && DottedLine.DottedLine.angle > 268)
{
AudioSource my_audio = GameObject.Find("SDir").GetComponent<AudioSource>();
my_audio.Play();
pointA.Set(MyBall.GetComponent<Transform>().position.x, pointA.y, pointA.z);
pointB.Set(MyBall.GetComponent<Transform>().position.x, pointB.y, pointB.z);
//DirDectect = false;
Invoke("DirDet", 0.7f);
}
if (DottedLine.DottedLine.angle < 2 || DottedLine.DottedLine.angle > 358)
{
AudioSource my_audio = GameObject.Find("SDir").GetComponent<AudioSource>();
my_audio.Play();
pointA.Set(pointA.x, MyBall.GetComponent<Transform>().position.y, pointA.z);
pointB.Set(pointB.x, MyBall.GetComponent<Transform>().position.y, pointB.z);
//DirDectect = false;
Invoke("DirDet", 0.7f);
}
if (DottedLine.DottedLine.angle < 182 && DottedLine.DottedLine.angle > 178)
{
AudioSource my_audio = GameObject.Find("SDir").GetComponent<AudioSource>();
my_audio.Play();
pointA.Set(pointA.x, MyBall.GetComponent<Transform>().position.y, pointA.z);
pointB.Set(pointB.x, MyBall.GetComponent<Transform>().position.y, pointB.z);
//DirDectect = false;
Invoke("DirDet", 0.7f);
}
}
if (DottedLine.DottedLine.angle > 2 && DottedLine.DottedLine.angle < 88 ||
DottedLine.DottedLine.angle > 92 && DottedLine.DottedLine.angle < 178 ||
DottedLine.DottedLine.angle > 182 && DottedLine.DottedLine.angle < 268 ||
DottedLine.DottedLine.angle > 272 && DottedLine.DottedLine.angle < 358)
{
DirDectect = true;
}
DottedLine.DottedLine.Instance.DrawDottedLine(pointA, pointB);
}
if (Input.touchCount > 0)
{
Touch touch = Input.GetTouch(0);
if (!EventSystem.current.IsPointerOverGameObject(Input.GetTouch(0).fingerId))
{
Vector2 worldPoint = Camera.main.ScreenToWorldPoint(Input.GetTouch(0).position);
RaycastHit2D hit = Physics2D.Raycast(worldPoint, Camera.main.transform.forward);
if (hit.collider.tag != null)
{
if (touch.phase == TouchPhase.Began && hit.collider.tag != "mShape")
{
pointA = Camera.main.ScreenToWorldPoint(Input.GetTouch(0).position);
MyBall = Instantiate(Ball, new Vector2(pointA.x, pointA.y), Quaternion.identity);
}
if (touch.phase == TouchPhase.Moved && hit.collider.tag != "mShape")
{
ShowDir = true;
}
if (touch.phase == TouchPhase.Ended && hit.collider.tag != "mShape")
{
if (wrapActive)
{
MyBall.AddComponent<wrap>();
}
MyBall.GetComponent<Rigidbody2D>().velocity = (pointB - MyBall.transform.position).normalized * speed;
HintShow.SetActive(false);
HintBtn.interactable = false;
SkipBtn.interactable = false;
ShowDir = false;
DesTime = true;
}
}
}
}
else
{
Debug.Log("NULL");
}
SOLUTION
if(Input.touchCount > 0 )
{
Touch touch = Input.GetTouch(0);
if(ShowDir)
{
pointB = Camera.main.ScreenToWorldPoint(Input.GetTouch(0).position);
pointB.z = Ball.transform.position.z;
if (DirDectect)
{
if (DottedLine.DottedLine.angle < 92 && DottedLine.DottedLine.angle > 88)
{
AudioSource my_audio = GameObject.Find("SDir").GetComponent<AudioSource>();
my_audio.Play();
pointA.Set(MyBall.GetComponent<Transform>().position.x, pointA.y, pointA.z);
pointB.Set(MyBall.GetComponent<Transform>().position.x, pointB.y, pointB.z);
Invoke("DirDet", 0.7f);
}
if (DottedLine.DottedLine.angle < 272 && DottedLine.DottedLine.angle > 268)
{
AudioSource my_audio = GameObject.Find("SDir").GetComponent<AudioSource>();
my_audio.Play();
pointA.Set(MyBall.GetComponent<Transform>().position.x, pointA.y, pointA.z);
pointB.Set(MyBall.GetComponent<Transform>().position.x, pointB.y, pointB.z);
Invoke("DirDet", 0.7f);
}
if (DottedLine.DottedLine.angle < 2 || DottedLine.DottedLine.angle > 358)
{
AudioSource my_audio = GameObject.Find("SDir").GetComponent<AudioSource>();
my_audio.Play();
pointA.Set(pointA.x, MyBall.GetComponent<Transform>().position.y, pointA.z);
pointB.Set(pointB.x, MyBall.GetComponent<Transform>().position.y, pointB.z);
Invoke("DirDet", 0.7f);
}
if (DottedLine.DottedLine.angle < 182 && DottedLine.DottedLine.angle > 178)
{
AudioSource my_audio = GameObject.Find("SDir").GetComponent<AudioSource>();
my_audio.Play();
pointA.Set(pointA.x, MyBall.GetComponent<Transform>().position.y, pointA.z);
pointB.Set(pointB.x, MyBall.GetComponent<Transform>().position.y, pointB.z);
Invoke("DirDet", 0.7f);
}
}
if (DottedLine.DottedLine.angle > 2 && DottedLine.DottedLine.angle < 88 ||
DottedLine.DottedLine.angle > 92 && DottedLine.DottedLine.angle < 178 ||
DottedLine.DottedLine.angle > 182 && DottedLine.DottedLine.angle < 268 ||
DottedLine.DottedLine.angle > 272 && DottedLine.DottedLine.angle < 358)
{
DirDectect = true;
}
DottedLine.DottedLine.Instance.DrawDottedLine(pointA, pointB);
}
if(!EventSystem.current.IsPointerOverGameObject(Input.GetTouch(0).fingerId)){
Vector2 worldPoint = Camera.main.ScreenToWorldPoint(Input.GetTouch(0).position);
RaycastHit2D hit = Physics2D.Raycast(worldPoint, Camera.main.transform.forward);
if (hit.collider.tag != null ){
//BEGIN
if (touch.phase == TouchPhase.Began && hit.collider.tag != "mShape" && MoveFalse )
{
BlockCode = false;
pointA = Camera.main.ScreenToWorldPoint(Input.GetTouch(0).position);
MyBall = Instantiate(Ball, new Vector2(pointA.x, pointA.y), Quaternion.identity);
}
if (touch.phase == TouchPhase.Began && hit.collider.tag == "mShape" && MoveFalse)
{
BlockCode = true;
}
if (!BlockCode)
{
//MOVE
if (touch.phase == TouchPhase.Moved && hit.collider.tag != "mShape")
{
ShowDir = true;
mShapeClicked = false;
MoveFalse = false;
Debug.Log("MOVE");
}
if (touch.phase == TouchPhase.Moved && hit.collider.tag == "mShape")
{
ShowDir = true;
mShapeClicked = true;
MoveFalse = false;
Debug.Log("OverShape");
}
//NO-MOVE
if (touch.phase == TouchPhase.Stationary && hit.collider.tag != "mShape")
{
ShowDir = true;
mShapeClicked = false;
MoveFalse = false;
Debug.Log("NoMove");
}
if (touch.phase == TouchPhase.Stationary && hit.collider.tag == "mShape")
{
ShowDir = true;
mShapeClicked = true;
MoveFalse = false;
Debug.Log("NoMove");
}
//END
if (touch.phase == TouchPhase.Ended)
{
MoveFalse = false;
mShapeClicked = false;
ShowDir = false;
DesTime = true;
Debug.Log("END");
if (wrapActive)
{
MyBall.AddComponent<wrap>();
}
if (!mShapeClicked)
{
MyBall.GetComponent<Rigidbody2D>().velocity = (pointB - MyBall.transform.position).normalized * speed;
}
HintShow.SetActive(false);
HintBtn.interactable = false;
SkipBtn.interactable = false;
}
}
}
}
}