//handles what happens when cards are attempted to be put onto each type of card holding location public void OnDrop(PointerEventData pointerData) { DraggableObject droppedCard = pointerData.pointerDrag.GetComponent <DraggableObject>(); CardInfo droppedCardInfo = pointerData.pointerDrag.GetComponent <CardInfo>(); //make sure card being dropped here can be moved if (droppedCard != null && droppedCard.GetComponent <DraggableObject>().canBeDragged == true && droppedCard.oldParent.GetComponent <CardDropArea>().myDropAreaType != CardDropArea.DropAreaType.FOUNDATION) { //check to make sure the move is valid if (rules.isMoveValid(this, pointerData.pointerDrag.GetComponent <CardInfo>())) { droppedCard.oldParent.GetComponent <CardDropArea>().cardStack.Pop(); droppedCard.oldParent = this.transform; //check for empty stacks if (cardStack.Count != 0) { cardStack.Peek().GetComponent <DraggableObject>().setCanBeDragged(false); } cardStack.Push(pointerData.pointerDrag); //handle each type of area switch (myDropAreaType) { case DropAreaType.TABLEAU: { droppedCard.GetComponent <DraggableObject>().setCanBeDragged(false); rules.updateStacks(); break; } case DropAreaType.FREECELL: { rules.updateStacks(); break; } case DropAreaType.FOUNDATION: { droppedCard.GetComponent <DraggableObject>().setCanBeDragged(false); Instantiate <ParticleSystem>(rules.successParticle, droppedCard.transform); rules.updateStacks(); break; } } } } //rules.updateStacks(); rules.checkForWin(); }
// Update is called once per frame void Update() { if (RoundManager.instance != null && RoundManager.instance.gameOver) { return; } if (Input.GetMouseButtonDown(0)) { Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); Debug.DrawRay(ray.origin, ray.direction * 10, Color.yellow); RaycastHit hit; Debug.Log("CASTING RAY : " + ray + " on layer " + itemLayerMask); if (Physics.Raycast(ray, out hit, Mathf.Infinity, itemLayerMask)) { Debug.Log("HIT OBJECT : " + hit.collider.gameObject.name); DraggableObject d = hit.collider.gameObject.GetComponentInParent <DraggableObject>(); if (d != null && Vector3.Distance(d.transform.position, MovementController.instance.backpack.transform.position) <= maxReach) { Rigidbody r = d.GetComponent <Rigidbody>(); r.useGravity = true; r.isKinematic = false; d.mouseIsDown = true; curDraggable = d; AudioManager.instance.PlayClick(); lineRenderer.enabled = true; lineRenderer.SetPosition(0, MovementController.instance.backpack.transform.position); lineRenderer.SetPosition(1, d.transform.position); } } } else if (Input.GetMouseButtonUp(0) && curDraggable != null) { AudioManager.instance.PlayRelease(); curDraggable.mouseIsDown = false; curDraggable = null; lineRenderer.enabled = false; } else if (lineRenderer.enabled && curDraggable != null) { lineRenderer.SetPosition(0, MovementController.instance.backpack.transform.position); lineRenderer.SetPosition(1, curDraggable.transform.position); } }