- Home /
Question by
willianbrasil · Jan 19, 2018 at 09:26 PM ·
2dtouchtouchphase
Touch.phase firing twice
Hi guys i'm using unity remote 5 to test this, i'm not sure if its imprecise but, i've tried using Input.GetTouch(0).phase and GetMouseButtonDown/Up(0), both are being fired twice rarely, its not happening in every touch, i'm sure that this isn't a double script problem neither a double object problem also i'm not using OnGUI, i've searched everywhere but haven't found a problem like this one.
if (Input.touchCount > 0) {
if (ma_mode == false)
{
if (Input.GetTouch(0).phase == TouchPhase.Began)
{
Debug.Log("beg");
touchPos2D = Camera.main.ScreenToWorldPoint(Input.GetTouch(0).position);
objInfo = Physics2D.Raycast(touchPos2D, Camera.main.transform.forward, 1f, touch_layers);
if (objInfo)
{
touchBegin = objInfo.collider.gameObject;
if (touchBegin.layer == 5)
{
Animator a = touchBegin.GetComponent<Animator>();
a.SetBool("isOver", true);
a.SetBool("hasClicked", false);
if (touchBegin.CompareTag("I12"))
{
if (objSelected.layer == 9)
{
turret_script.Activate_Skill();
}
else if (objSelected.layer == 10)
{
trap_script.Activate_Skill();
}
}
}
}
else
{
touchBegin = null;
if (enabledUI)
{
enabledUI = false;
Disable_UI();
objSelected = null;
}
else if (isSelected)
{
if (objSelected.layer == 9)
{
if (turret_script.HasSkill)
skill_icon.SetActive(false);
sell_icon.SetActive(false);
repair_icon.SetActive(false);
turret_script.Cancel_Skill();
isSelected = false;
objSelected = null;
}
else if (objSelected.layer == 10)
{
if (trap_script.HasSkill)
skill_icon.SetActive(false);
sell_icon.SetActive(false);
trap_script.Cancel_Skill();
isSelected = false;
objSelected = null;
}
}
}
}
else if (Input.GetTouch(0).phase == TouchPhase.Moved)// Camera Movement
{
Vector2 touchDeltaPosition = Input.GetTouch(0).deltaPosition;
Camera.main.transform.Translate(-touchDeltaPosition.x * cameraSpeed, -touchDeltaPosition.y * cameraSpeed, 0);
}
else if (Input.GetTouch(0).phase == TouchPhase.Ended)
{
touchPos2D = Camera.main.ScreenToWorldPoint(Input.GetTouch(0).position);
Debug.Log("End");
objInfo = Physics2D.Raycast(touchPos2D, Camera.main.transform.forward, 1f, touch_layers);
if (objInfo)
{
touchedObj = objInfo.collider.gameObject;
}
else
{
touchedObj = null;
if (enabledUI)
{
enabledUI = false;
Disable_UI();
objSelected = null;
}
else if (isSelected)
{
if (objSelected.layer == 9)
{
if (turret_script.HasSkill)
skill_icon.SetActive(false);
sell_icon.SetActive(false);
repair_icon.SetActive(false);
turret_script.Cancel_Skill();
isSelected = false;
objSelected = null;
}
else if (objSelected.layer == 10)
{
if (trap_script.HasSkill)
skill_icon.SetActive(false);
sell_icon.SetActive(false);
trap_script.Cancel_Skill();
isSelected = false;
objSelected = null;
}
}
}
if (touchBegin != null)
{
if (touchBegin == touchedObj)
{
if (touchedObj.layer == 5)
{
Animator a = touchedObj.GetComponent<Animator>();
a.SetBool("isOver", false);
a.SetBool("hasClicked", true);
}
TouchedObj_Testing();
}
else if (touchBegin.layer == 5)
{
touchBegin.GetComponent<Animator>().SetBool("isOver", false);
}
}
}
}
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220612150854im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
why is my exported apk has some kind of difference with the editor, editor+unity remote 0 Answers
Placing a Rect and detecting a Touch/Tap 1 Answer
Looking for a touch based rigidbody2d.moveposition advice 1 Answer
Touch Buttons 0 Answers
Swipe horizontally and hold finger down to move character? 1 Answer