/** * Use this object on a specific target */ public void Use(GameObject target, bool shouldDestroyAfterUse = false) { //Trigger the particles and sound //If shouldDestroyAfterUse is true, then destroy this object //Finally, do whatever after used UseTarget TargetUse = target.GetComponent <UseTarget>(); if (TargetUse != null) { TargetUse.Use(); if (specialEffect != null) { specialEffect.Play(); } if (sound != null) { sound.PlayOneShot(audioClip); } if (shouldDestroyAfterUse) { Destroy(gameObject); } } if (doAfterBeingUsed != null) { doAfterBeingUsed.Invoke(); } }
/** * Use this object on whatever is in front of the * character */ public void Use(bool shouldDestroyAfterUse = false) { //Get the object in front of this player //Call Use(useTarget, shouldDestroyAfterUse) RaycastHit hit; // Does the ray intersect any objects excluding the player layer //Raycast is used to detect the front of the player if (Physics.Raycast(transform.parent.parent.position, transform.forward, out hit, maxDistance)) { UseTarget TargetUse = hit.collider.gameObject.GetComponent <UseTarget>(); if (TargetUse != null) { TargetUse.Use(); if (specialEffect != null) { specialEffect.Play(); } if (sound != null) { sound.PlayOneShot(audioClip); } if (shouldDestroyAfterUse) { Destroy(gameObject); } if (doAfterBeingUsed != null) { doAfterBeingUsed.Invoke(); } } } }