public void DropHeld() { print("Location: " + transform.position); GetComponent <AudioSource>().PlayOneShot(placeSFX); ChildBeta child = held.GetComponent <ChildBeta>(); if (child) { //Holding a child! See if it needs to become free roaming NavMeshHit hit; if (NavMesh.SamplePosition(inFront, out hit, dropDist, NavMesh.AllAreas)) { //Drop the child! print("Child is getting dropped into Navmesh!"); held.transform.position = inFront; held.SetActive(true); held.GetComponent <NavMeshAgent>().enabled = true; held.GetComponent <BoxCollider>().enabled = true; child.enabled = true; child.StopGrab(); held = null; print("Child has finished being dropped!"); Destroy(holdDisplay); return; } } //Attempt drop if (ObjectPlacement.instance.Drop(held, inFront)) { held.SetActive(true); held = null; Destroy(holdDisplay); } else { print("Hwat. How has this happened."); } }
// Update is called once per frame void Update() { inFront = transform.position + transform.forward * pickupDistance; ObjectPlacement.instance.SignalPosition(inFront); /*if (holdingChild) //the "child" is a child of the player transform * { * if (Input.GetKeyDown(pickupKey)); * { * print("Location: " + inFront); * //Attempt drop * if (ObjectPlacement.instance.Drop(held, inFront)) * { * held.SetActive(true); * held = null; * } * else * { * print("Hwat."); * } * * } * * } * else * {*/ if (Input.GetKeyDown(pickupKey)) // && gridLogicActive) { if (held) { print("Location: " + transform.position); GetComponent <AudioSource>().PlayOneShot(placeSFX); ChildBeta child = held.GetComponent <ChildBeta>(); if (child) { //Holding a child! See if it needs to become free roaming NavMeshHit hit; if (NavMesh.SamplePosition(inFront, out hit, dropDist, NavMesh.AllAreas)) { //Drop the child! print("Child is getting dropped into Navmesh!"); held.transform.position = inFront; held.SetActive(true); held.GetComponent <NavMeshAgent>().enabled = true; held.GetComponent <BoxCollider>().enabled = true; child.enabled = true; child.StopGrab(); held = null; print("Child has finished being dropped!"); Destroy(holdDisplay); anim.SetTrigger("Place"); anim.SetBool("Holding", false); return; } } //Attempt drop if (ObjectPlacement.instance.Drop(held, inFront)) { held.SetActive(true); held = null; anim.SetTrigger("Place"); anim.SetBool("Holding", false); Destroy(holdDisplay); } else { print("Hwat. How has this happened."); } } else { GameObject child = ChildNearby(); //Check for child pickup if (child) { GetComponent <AudioSource>().PlayOneShot(pickupSFX); anim.SetTrigger("Grab"); //Halt, because the children are currently the ones who signal use Pickup(child); GetComponent <AudioSource>().PlayOneShot(pickupSFX); //Child currently doesn't do anything once picked up, so we disable it ChildBeta childComp = child.GetComponent <ChildBeta>(); childComp.GetGrabbed(); //TODO: Figure out if this is necessary? //Could be fun to have the child struggle once you pick them up childComp.enabled = false; child.GetComponent <BoxCollider>().enabled = false; child.GetComponent <Rigidbody>().useGravity = false; child.tag = "Untagged"; child.SetActive(false); } else { //No child found, check pick up a game object instead GameObject found = ObjectPlacement.instance.PickUp(inFront); if (found) { anim.SetTrigger("PickUp"); Pickup(found); } if (held) { anim.SetBool("Holding", true); GetComponent <AudioSource>().PlayOneShot(pickupSFX); held.SetActive(false); } } } } }