private void HandleInput() { if (objectLookedAt != null && Input.GetButtonDown("Activate")) { objectLookedAt.DoActivate(); } }
private void HandleInput() { if (lookedAtObject != null && Input.GetButtonDown("Activate")) { Debug.Log("This is an IActivatable!"); lookedAtObject.DoActivate(); } }
private void ActivateLookedAtObject() { if (objectLookedAt != null) { if (Input.GetButtonDown("Fire1")) { objectLookedAt.DoActivate(); } } }
private void ActivateLookedAtObject() { if (objectLookedAt != null) { if (Input.GetButtonDown("Fire1")) { objectLookedAt.DoActivate(); canvas.GenerateMenuItems(); } } }
private void CheckedForLookedAtOBjectObjects() { RaycastHit raycastHit; if (Physics.Raycast(transform.position, transform.forward, out raycastHit, maxDistanceToActivateObjects, layerActivatableObjectsAreOn)) { //if our ray hits something, we go into this code block objectLookedAt = raycastHit.collider.gameObject.GetComponent <IActivatable>(); userInput = raycastHit.collider.gameObject.GetComponent <Icommand>(); if (objectLookedAt == null) { // attack(); throw new System.Exception(raycastHit.collider.gameObject.name + " MUST have a script that implements IActivatable script attached to it."); } string objectName = raycastHit.collider.gameObject.name; //Debug.Log("Object Looked at " + objectName); if (Input.GetButton("xButton")) { if (gameObject.tag == "Items") { raycastHit.collider.gameObject.SetActive(false); Debug.Log("The user is looking at an activatable Object, and now has clicked."); objectLookedAt.DoActivate(); userInput.DoCommand(); } userInput.DoCommand(); } } else { objectLookedAt = null; userInput = null; } Vector3 endPoint = transform.position + maxDistanceToActivateObjects * transform.forward; Debug.DrawLine(transform.position, endPoint, Color.red); }
// Update is called once per frame void Update() { Debug.DrawRay(transform.position, transform.forward * maxActivateDistance, Color.red); RaycastHit raycastHit; if (Physics.Raycast(transform.position, transform.forward, out raycastHit, maxActivateDistance)) { Debug.Log("Raycast hit" + raycastHit.transform.name); IActivatable objectLookedAt = raycastHit.transform.GetComponent <IActivatable>(); if (objectLookedAt != null && Input.GetButtonDown("Activate")) { objectLookedAt.DoActivate(); } } }