public void OnUpdate() { //PC端鼠标左键点击 if (Input.GetMouseButtonDown(0)) { Vector2 touchPos = Camera.main.ScreenToWorldPoint(Input.mousePosition); RaycastHit2D hit = Physics2D.Raycast(touchPos, Vector2.down, touchThreshold, groundedLayerMask.value); if (hit.collider != null) { m_destPos = touchPos; sakura.SetSakura(new Vector3(m_destPos.x, m_destPos.y, this.transform.position.z)); //控制人物转向 if (m_destPos.x < m_rigidbody2D.position.x) { Debug.Log("左转"); if (this.gameObject.CompareTag("Boy")) { m_renderer.flipX = true; } if (this.gameObject.CompareTag("Girl")) { m_renderer.flipX = false; } } else { Debug.Log("右转"); if (this.gameObject.CompareTag("Boy")) { m_renderer.flipX = false; } if (this.gameObject.CompareTag("Girl")) { m_renderer.flipX = true; } } } } //Android端单击 if (Input.touchCount == 1) { Touch touch = Input.touches[0]; if (touch.phase == TouchPhase.Ended) { Vector2 touchPos = Camera.main.ScreenToWorldPoint(touch.position); RaycastHit2D hit = Physics2D.Raycast(touchPos, Vector2.down, touchThreshold, groundedLayerMask.value); if (hit.collider != null) { m_destPos = touchPos; sakura.SetSakura(new Vector3(m_destPos.x, m_destPos.y, this.transform.position.z)); //控制人物转向 if (m_destPos.x < m_rigidbody2D.position.x) { Debug.Log("左转"); if (this.gameObject.CompareTag("Boy")) { m_renderer.flipX = true; } if (this.gameObject.CompareTag("Girl")) { m_renderer.flipX = false; } } else { Debug.Log("右转"); if (this.gameObject.CompareTag("Boy")) { m_renderer.flipX = false; } if (this.gameObject.CompareTag("Girl")) { m_renderer.flipX = true; } } } } } //Debug.Log("更新目的地,目的地为:" + m_destPos); //控制动画播放 }
//此处也分流,分为人物点击判断与人物行走点击判断 //暂时先不在InitSetting中设置双人模式与单人模式而调用不同的单例,看第3关要不要整合先 public void OnUpdate() { //PC端鼠标左键点击 if (Input.GetMouseButtonDown(0)) { Vector2 touchPos = Camera.main.ScreenToWorldPoint(Input.mousePosition); //点人的话就返回 if (m_capsule.bounds.Contains(touchPos)) { setWhoInControl(0); return; } else if (m_girlCapsuleCollider2D.bounds.Contains(touchPos)) { setWhoInControl(1); return; } RaycastHit2D hit = Physics2D.Raycast(touchPos, Vector2.down, touchThreshold, groundedLayerMask.value); if (hit.collider != null) { m_destPos = touchPos; sakura.SetSakura(new Vector3(m_destPos.x, m_destPos.y, this.transform.position.z)); //控制人物转向 if (m_destPos.x < m_rigidbody2D.position.x) { Debug.Log("左转"); if (m_whoInControl == 0) { m_renderer.flipX = true; } if (m_whoInControl == 1) { m_girlRenderer.flipX = false; } } else { Debug.Log("右转"); if (m_whoInControl == 0) { m_renderer.flipX = false; } if (m_whoInControl == 1) { m_girlRenderer.flipX = true; } } } } //Android端单击 if (Input.touchCount == 1) { Touch touch = Input.touches[0]; if (touch.phase == TouchPhase.Ended) { Vector2 touchPos = Camera.main.ScreenToWorldPoint(touch.position); if (m_capsule.bounds.Contains(touchPos)) { m_whoInControl = 0; return; } else if (m_girlCapsuleCollider2D.bounds.Contains(touchPos)) { m_whoInControl = 1; return; } RaycastHit2D hit = Physics2D.Raycast(touchPos, Vector2.down, touchThreshold, groundedLayerMask.value); if (hit.collider != null) { m_destPos = touchPos; sakura.SetSakura(new Vector3(m_destPos.x, m_destPos.y, this.transform.position.z)); //控制人物转向 if (m_destPos.x < m_rigidbody2D.position.x) { Debug.Log("左转"); if (m_whoInControl == 0) { m_renderer.flipX = true; } if (m_whoInControl == 1) { m_girlRenderer.flipX = false; } } else { Debug.Log("右转"); if (m_whoInControl == 0) { m_renderer.flipX = false; } if (m_whoInControl == 1) { m_girlRenderer.flipX = true; } } } } } //Debug.Log("更新目的地,目的地为:" + m_destPos); //控制动画播放 }