//Handle Collision, with what is presumed is a ring. private void HandleCollision(Collider2D collision) { GameObject collidingRing; RingBehaviour collidingRingBehaviour; //Get the collider and its ringbehaviour component. // Collision with the Ring, ie Player if (collision.gameObject.tag == "Player") { collidingRing = collision.gameObject; collidingRingBehaviour = collidingRing.GetComponent <RingBehaviour>(); } else { return; } // if the user wants to use the snap functionality if (GameManager.instance.useSnapFunctionality) { if (isSnapped) { AddToPin(collidingRingBehaviour); } } if (collidingRingBehaviour.GetIsMoving()) // If we are moving the ring, cant add it then. { return; } if (parentPinBehaviour.GetRingsOnThisPin().Contains(collidingRingBehaviour)) // If the pin already contains this ring, cant add it again. { return; } if (IsOkToLand(collidingRing)) // If we are above or same level as the pin when colliding. { if (parentPinBehaviour.GetAmountOfRingsOnThisPin() == 0) // are we first on this pin? (parent pin) { AddToPin(collidingRingBehaviour); } else { if (CheckIfPinHasRings()) // If there are any other rings on this pin { //if yes, check size on the top ring on the pin if (CheckSizeOnTopRing(collidingRingBehaviour)) { //The ring on the pin is bigger, so we can add this smaller one to the pin. AddToPin(collidingRingBehaviour); }//Else, would be some implementation if the ring that we are dropping is bigger than the one on the pin. } } } }
/// <summary> MOUSE VERSION /// Returns the Ring as Gameobject if raycast hit. Else return null. /// </summary> /// <returns>Gameobject</returns> GameObject GetSelectedRingMouse() { // No need for raycast if a ring is already selected. if (SelectedRing != null) { return(SelectedRing); } RaycastHit2D hit = RayCast(); // If we did not hit anything that we wanted, just return null. if (!hit) { return(null); } //If we hit a Ring if (hit.transform.gameObject.GetComponent <RingBehaviour>()) { return(hit.transform.gameObject); } //If we hit a PinBehaviourObject if (hit.transform.gameObject.GetComponent <PinBehaviour>()) { PinBehaviour temp = hit.transform.gameObject.GetComponent <PinBehaviour>(); if (temp.GetAmountOfRingsOnThisPin() != 0) // and there is a ring on the pin { return(temp.GetRingsOnThisPin()[temp.GetAmountOfRingsOnThisPin() - 1].gameObject); //return top ring. } } //If nothing else, return null return(null); }