public override void Awake() { base.Awake(); _uiController = FindObjectOfType <UIController>(); _platesController = FindObjectOfType <PlatesController>(); _ringsController = FindObjectOfType <RingsController>(); }
// Update is called once per frame void Update() { Vector3 newPos; Vector3 touchPos; int i = 0; int id = 0; //if using finger //Touch[] touches = Input.touches; //if (Input.touchCount == 1) //{ // touchPos = touches[0].position; // //id = touches[0].fingerId; //} //else //{ // return; //} //else //{ touchPos = Input.mousePosition; //} //for(int i = 0; i < Input.touchCount; i++) //{ //OnMouseDown() //if(touches[i].phase == TouchPhase.Began) if (Input.GetMouseButtonDown(0)) { var ray = Camera.main.ScreenPointToRay(touchPos); if (Physics.Raycast(ray, out RaycastHit hit)) { // if it hit a plate if (hit.collider != null && hit.transform.CompareTag("plate")) { Debug.Log("Plate touched"); //check if this plate is draggable PlatesController platesController = hit.collider.GetComponent <PlatesController>(); if (platesController.isDraggable) { draggedObj = hit.transform.gameObject; dist = Camera.main.WorldToScreenPoint(hit.transform.position).z; newPos = Camera.main.ScreenToWorldPoint(new Vector3(touchPos.x, touchPos.y, dist)); offset = hit.transform.position - newPos; SelectPlate(draggedObj); } } //if select conveyer/chef/sauce plate/camera else if (hit.collider != null && hit.collider.name != "Plane" && hit.collider.name != "Sphere") { if (isSelected) { //if the original selected object is same as now if (selectedObj.transform.CompareTag(hit.transform.tag)) { //just de-select it DeselectHandler(selectedObj); } else { //de-select the original one DeselectHandler(selectedObj); //select current one SelectHandler(hit.transform.gameObject); } } else { SelectHandler(hit.transform.gameObject); } } } } //OnMouseDrag //if( touches[i].phase == TouchPhase.Moved || touches[i].phase == TouchPhase.Stationary) if ((Input.GetMouseButton(0)) && draggedObj != null) { //Debug.Log("Plate dragged"); newPos = Camera.main.ScreenToWorldPoint(new Vector3(touchPos.x, touchPos.y, dist)); draggedObj.transform.position = newPos + offset; } //OnMouseUp //if( touches[i].phase == TouchPhase.Ended || touches[i].phase == TouchPhase.Canceled) if ((Input.GetMouseButtonUp(0)) && draggedObj != null) { Debug.Log("Plate Released"); DeselectHandler(draggedObj); draggedObj = null; } //} }