bool TryDropCard(Collider2D c) { //Only test for the first collider that player is touching CardDropoff dropOff = c.GetComponent <CardDropoff>(); //Also ignore totally if dropoff already has all of its cards (but don't send card away) if (dropOff == null || dropOff != wordCollider || !dropOff.CanTakeCard()) { return(false); } if (holding && buttonFixedPressed) { //Increment drop counter TotalDrops += 1; //Check if correct card //Unclear if card can be dropped if it's still wrong //To prevent backtracking it could fly back to where it came from CardPickup cardPickup = holding.GetComponent <CardPickup>(); if (!dropOff.IsSolution(cardPickup)) { IncorrectDrops += 1; //Send back to where it came from //Play some kind of negative sound AudioSource.PlayClipAtPoint(SoundManager.GetClip("ring_down"), transform.position); cardPickup.GetComponent <BoxCollider2D>().enabled = true; cardPickup.MoveHome(); //Action was completed, no input should have more than one action happen } else { CorrectDrops += 1; //Remove CardPickup monobehaviour //Or set flag to prevent pickup again of card (dropoff may be one way) //Trigger is already disabled dropOff.GiveCard(holding); //Play positive sound AudioSource.PlayClipAtPoint(SoundManager.GetClip("ring_up"), transform.position); //Change color of text textColor = CompletionColor; var textMesh = dropOff.UITextMesh; textMesh.color = CompletionSelectionColor; } holding = null; didActionThisFrame = true; return(true); } else { return(false); } }
public void GiveCard(Transform holding) { //Perform some kind of animation //Make some sort of success sound //Shoot out some sort of particles holding.SetParent(transform); //Make it move back to its home but this time in a new location CardPickup pickup = holding.GetComponent <CardPickup>(); pickup.HomeLocation.position = transform.position + Vector3.down; pickup.MoveHome(); tookCard = true; }