public void Use() { if (isOpen) { onDoorOpened?.Invoke(this); SceneManager.LoadScene(_targetScene); } else { onDoorOpenFailed?.Invoke(this); } }
// Update is called once per frame void Update() { Debug.DrawRay(transform.position, transform.forward * distanceToSee, Color.cyan); if (Physics.Raycast(this.transform.position, this.transform.forward, out hit, distanceToSee)) { //Debug.Log("I touched " + hit.collider.gameObject.name); } //on click if (Input.GetKeyDown(KeyCode.E)) { //draw ray RaycastHit[] rayHits; var ray = Camera.main.ScreenPointToRay(Input.mousePosition); rayHits = Physics.RaycastAll(ray, distanceToSee, interactionsLayer); //checking every hit, so see if they match the tags for (int i = 0; i < rayHits.Length; i++) { //Debug.Log("With the new Raycast, I touched " + rayHits[i].collider.gameObject.name); if (rayHits[i].collider.gameObject.tag == "ForwardDoor") { GoForwards.Invoke(); source.PlayOneShot(door1); } else if (rayHits[i].collider.gameObject.tag == "BackDoor") { GoBack.Invoke(); source.PlayOneShot(door2); } else if (rayHits[i].collider.gameObject.tag == "ExitDoor") { source.PlayOneShot(door3); EventManager.TriggerEvent("ThroughExitDoor"); } else if (rayHits[i].collider.gameObject.tag == "Snowball") { if (!onlyOnce) { onlyOnce = true; var snowball = rayHits[i].collider.gameObject.GetComponent <SnowballScript>(); if (snowball != null) { snowball.GotFound(); source.PlayOneShot(snow); invSnow++; Debug.Log("Found snowball"); } Invoke("PickUpBall", 1f); } } else if (rayHits[i].collider.gameObject.tag == "Lantern") { var lantern = rayHits[i].collider.gameObject.GetComponent <Lantern>(); if (lantern != null) { if (invSnow <= 0) { if (hasLighter || hasMatches) { lantern.LightItUp(); if (hasLighter) { source.PlayOneShot(lightItUp); } else if (hasMatches) { source.PlayOneShot(lightItUp2); } } else { return; } } else { if (firstBall) { firstBall = false; } lantern.AddBall(); invSnow--; source.PlayOneShot(snow2); } } } else if (rayHits[i].collider.gameObject.tag == "Lighter") { hasLighter = true; Destroy(rayHits[i].collider.gameObject); source.PlayOneShot(lighter); } else if (rayHits[i].collider.gameObject.tag == "Matches") { hasLighter = true; Destroy(rayHits[i].collider.gameObject); source.PlayOneShot(matches); } } } }