// Use this for initialization void Start() { System.Random rng = new System.Random(Time.time.ToString().GetHashCode()); int rows = rng.Next(5, 7); int cols = rng.Next(5, 7); float rowsMultiplier = 16.5f; float colsMultiplier = 32.0f; float colMaxSize = (cols + 1) * colsMultiplier; float rowMaxSize = (rows + 1) * rowsMultiplier; Iinteractable storageData = warehouse.GetComponentInChildren <Iinteractable>(); TextMesh StorageTitleOutside = warehouse.GetComponentInChildren <TextMesh>(); GameObject floor; floor = Instantiate(floorPrefab) as GameObject; floor.transform.localScale = new Vector3(colMaxSize, rowMaxSize, 1); floor.transform.position = new Vector3((colMaxSize - 2 * colsMultiplier) / 2, 0, (rowMaxSize - 2 * rowsMultiplier) / 2); int number = 0; for (int i = 0; i < rows; i++) { for (int j = 0; j < cols; j++) { number = (i * cols) + j; storageData.title = "Storage " + number; GameObject wasuwasol = Instantiate(warehouse.transform, transform.position + new Vector3(i * colsMultiplier, 0, j * rowsMultiplier), transform.rotation) as GameObject; //Debug.Log(wasuwasol.gameObject); } } }
void OnTriggerExit(Collider other) { if (other.gameObject.GetComponent <Iinteractable>() != null && other.gameObject.GetComponent <Iinteractable>() == nearbyInteractable) { infoUI.removeInteractable(nearbyInteractable); nearbyInteractable = null; } }
void OnTriggerEnter(Collider other) { if (other.gameObject.GetComponent <Iinteractable>() != null) { nearbyInteractable = other.gameObject.GetComponent <Iinteractable>(); infoUI.addInteractable(nearbyInteractable); } }
void CheckForInteraction() { RaycastHit2D rh2d = Physics2D.Raycast(((Vector2)transform.position + gGM.moveUtil.raycastOffset), gGM.lastFacingDirection, gGM.moveUtil.tileSize, mask); if (rh2d.transform != null) { Iinteractable interacterface = rh2d.transform.gameObject.GetComponent <Iinteractable>(); if (interacterface != null) { interacterface.Interact(); } } }
private void LookForObject() { Ray ray = mainCamera.ViewportPointToRay(new Vector3(0.5f, 0.5f, 0)); RaycastHit hitInfo; if (Physics.Raycast(ray, out hitInfo, distance, interactableLayer)) { currentInteractable = hitInfo.collider.GetComponent <Iinteractable>(); interactCanvas.enabled = true; interactText.text = "Press E to interact"; } else { currentInteractable = null; interactCanvas.enabled = false; } }
// Update is called once per frame void Update() { RaycastHit hit; float distance; //Vector3 forward = transform.TransformDirection(Vector3.forward)*2; //Vector3 up = transform.TransformDirection(Vector3.up) * 2; //Vector3 upRay = (Quaternion.AngleAxis(0.3f, up) * forward)*3; //Debug.Log("Update from raycast"); //Debug.DrawRay(transform.position, forward, Color.black); //Debug.DrawRay(transform.position, upRay, Color.black); //if (Physics.Raycast(transform.position, (forward), out hit, 2.0f)) Ray ray = Camera.ScreenPointToRay(Input.mousePosition); if (Physics.Raycast(ray, out hit) && hit.transform.tag == "Raycast") { distance = hit.distance; targetGameObject = hit.collider.gameObject; } else { targetGameObject = null; } if (Input.GetKeyDown(KeyCode.E)) { if (targetGameObject != null) { Iinteractable targetScript = (Iinteractable)targetGameObject.GetComponent(typeof(Iinteractable)); if (targetScript != null) { targetScript.PerformInteraction(); } else { Debug.Log("No target"); } } } }
private void CheckForCollide() { if (Physics.Raycast(playerSight, out hit, distance))//this occurs if the ray hits something... { interactableInstance = hit.collider.gameObject.transform.parent.GetComponent <Iinteractable>(); if (interactableInstance != null && interactableInstance.CanInteract()) { interactableInstance.HighlightObjectText(); if (inputButtonFloat > 0)//checks to see if you push the button { interactableInstance.Interact(); } } } else { interactText.gameObject.SetActive(false); } }
// Update is called once per frame void Update() { if (Input.GetButtonDown("Fire1")) { // Debug.Log("test"); RaycastHit hit; Ray ray; ray = (Camera.main.ViewportPointToRay(new Vector3(0.5f, 0.5f, 0f))); // ray to center of screen ray.origin = transform.position; if (Physics.Raycast(ray, out hit, range, Physics.DefaultRaycastLayers, QueryTriggerInteraction.Ignore)) { if (hit.rigidbody != null) { Iinteractable obj = hit.rigidbody.gameObject.GetComponent <Iinteractable>(); if (obj != null) { obj.OnStartAction(); } } } } }
void OnTriggerEnter(Collider other) { Debug.Log(other.gameObject); interaction_object = other; if (other.gameObject.CompareTag("interactable")) { if (can_interact) { interaction_available = true; interaction_gameobject = other.GetComponent<Iinteractable>(); } } if (other.gameObject.CompareTag("zombie")) { Debug.Log ("Game over"); pausedText.text = "Game over"; } if (other.gameObject.CompareTag ("door")) { door1 = other.gameObject.transform.GetChild (0); door2 = other.gameObject.transform.GetChild (1); if (door_open == false) { door1.GetComponent<DoorScript>().Open(); door2.GetComponent<DoorScript>().Open(); door_open = !door_open; } } }
public void Interaction(Iinteractable interactable) { interactable.Action(this); }