//Will do an interaction based on if it can be picked up (GiveObject script) or if it has dialogueSpawner script void DoInteract(GameObject interactObject) { if (interactObject != null) { if (interactObject.tag == "Object") { Debug.Log("You clicked on it"); //check if it has a dialogue spawner, if so, call it's OnClick DialogueSpawner showNarrative = interactObject.GetComponent <DialogueSpawner>(); if (showNarrative != null) { Debug.Log("Calling dialogue spawner."); //has a dialogue spawner showNarrative.OnClick(); } } GiveObject goScript = interactObject.GetComponent <GiveObject>(); if (goScript != null) { inventory.GiveItem((int)goScript.whichItem); Destroy(goScript.gameObject); SoundManager.instance.PlaySingle(SoundManager.instance.m_stingPickup); } } }
private void OnGiveObject(GiveObject e) { // @Improve! @FIX @HACK if (e.ObjectName == "Key") { inventory.hasKey = true; } if (e.ObjectName == "PowerObject") { inventory.hasPowerObject = true; } UpdateObjects(); }
// Update is called once per frame void Update() { RaycastHit hit; Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); if (EventSystem.current.IsPointerOverGameObject()) { // Debug.Log("Raycast blocked by clicking on UI element"); return; } if (Physics.Raycast(ray, out hit, 100, clickMask)) { UseItemOnThis uiotScript = hit.collider.GetComponent <UseItemOnThis>(); if (Input.GetMouseButtonUp(0)) { if (uiotScript != null) { if (uiotScript.hasAlreadyActed) { Debug.Log("Already got the item it needs"); return; } if (inventory.ItemIsSelected()) { if (inventory.UseCurrentItemIfAble(uiotScript)) { return; } } else { Debug.Log("No item selected"); } //return; } //If currently doing move to interact, interupt it early, and stop the coroutine that is polling distance if (moveToInteract) { moveToInteract = false; StopCoroutine(PollInteractDistance()); } //Click on a door to teleport player to adjacent room DoorTeleport teleportFrom = hit.collider.GetComponent <DoorTeleport>(); if (teleportFrom != null) { transform.position = teleportFrom.teleportDestination.transform.position; transform.rotation = teleportFrom.teleportDestination.transform.rotation; navMeshAgent.SetDestination(transform.position); SoundManager.instance.PlaySingle(SoundManager.instance.m_doorOpen); ToggleSecurityCamSfx(teleportFrom); return; //Debug.Log("I can teleport you"); } GiveObject goScript = hit.collider.GetComponent <GiveObject>(); if (goScript != null || hit.collider.tag == "Object") { //We have clicked on object that has dialogue or can be picked up, check if it is in range if (IsInInteractRange(transform.position, hit.transform.position)) { //In range, call the DoInteract function DoInteract(hit.collider.gameObject); } else //not in range, start moving towards it, try picking it up again after a short delay { //Set move to destination, Start co routine to check again soon interactHit = hit; //store what we clicked on, so we can check it again later moveToInteract = true; StartCoroutine(PollInteractDistance()); //start polling distance navMeshAgent.SetDestination(hit.point); } } else { navMeshAgent.SetDestination(hit.point); } } // end GetMouseButtonUp ObjectHighlight ohNow = hit.collider.GetComponent <ObjectHighlight>(); if (ohNow != mousedOverCurrently) { if (mousedOverCurrently != null) { mousedOverCurrently.mouseHoverRemoveTint(); } mousedOverCurrently = ohNow; if (mousedOverCurrently != null) { mousedOverCurrently.mouseHoverTint(); } } // end ohNow != mousedOverCurrently } // end Pyhsics.Raycast check }