// What to do when this item gets used. public override void Use() { staticNoise.volume = 0f; if (staticNoise == null) { print("fugg"); } AudioSource.PlayClipAtPoint(sound2play, Camera.main.transform.position); GameObject bed = GameObject.Find("mattress_18"); Destroy(bed.GetComponent <InteractiveBehaviour>()); //InteractiveBehaviour behave = new InteractiveBehaviour (); bed.AddComponent <InteractiveBehaviour>( ); GameObject bed2 = GameObject.Find("mattress_18"); InteractiveBehaviour bedBehave = bed2.GetComponent <InteractiveBehaviour>(); bedBehave.hint = "Go to sleep"; print(bedBehave.hint + " :should of hinted"); bedBehave.interactiveDescription = "yolo it"; bedBehave.timeToDisplay = 2.0f; DayOneSceneChange control = GameObject.FindGameObjectWithTag("controller").GetComponent <DayOneSceneChange>(); control.levelComplete = true; }
// Whenever the GUI redraws. void OnGUI() { // Raycast to check for interactive elements in front of you. Ray ray = Camera.main.ScreenPointToRay(new Vector3(Screen.width / 2, Screen.height / 2, 0)); RaycastHit hit; if (Physics.Raycast(ray, out hit)) { if (interactive(hit.collider.tag) && hit.distance < range) { GameObject obj = hit.collider.gameObject; InteractiveBehaviour ib = obj.GetComponent <InteractiveBehaviour>(); GUI.Label(new Rect(HINT_LEFT_OFFSET, Screen.height - HINT_BOTTOM_OFFSET, 300, 25), ib.hint); } } // Draw inventory. if (inventoryOpen) { for (int i = 0; i < NUM_ITEMS; i++) { // Compute position on screen to show item. Rect position = new Rect(LEFT_OFFSET + GAP * i + ITEM_WIDTH * i, Screen.height - ITEM_WIDTH - BOTTOM_OFFSET, ITEM_WIDTH, ITEM_WIDTH); // If there's an item in the slot get the content . GUIContent content; if (Inventory[i] == null) { content = new GUIContent(); } else { content = new GUIContent(string.Empty, Inventory[i].icon, Inventory[i].description); } // Make button, add listener. if (GUI.Button(position, content)) { if (Inventory[i] != null && Inventory[i].Usable()) { Inventory[i].Use(); if (Inventory[i].Consumable()) { Inventory[i] = null; } } } } // Display currently seleted tooltip (this is "GUI.tooltip"). GUI.Label(new Rect(TOOLTIP_LEFT_OFFSET, Screen.height - TOOLTIP_BOTTOM_OFFSET - 15, InventoryWidth(), 60), GUI.tooltip); } // Display current interactive display. if (interactiveDisplay != string.Empty) { // Check whether the display should be removed. float timeNow = Time.time; if (timeNow - timeStarted > timeToDisplay + FADEOUT) { interactiveDisplay = string.Empty; } // Display current interactive text. // Fade out if need be. else { // Position of interactive text. Rect position = new Rect(INTERACTIVE_LEFT_OFFSET, Screen.height - INTERACTIVE_BOTTOM_OFFSET - 15, InventoryWidth(), 60); // Set alpha based on time to fadeout. // Inject f : (0,FADEOUT) -> (0,1) // The input x is the amount of time of FADEOUT elapsed. float x = (timeToDisplay + FADEOUT) - (timeNow - timeStarted); float alpha = x / FADEOUT; float r = GUI.color.r; float g = GUI.color.g; float b = GUI.color.b; GUI.color = new Color(r, g, b, alpha); GUI.Label(position, interactiveDisplay); GUI.color = new Color(r, g, b, 1); } } }
// Update is called once per frame void Update() { if (Input.GetKeyDown(KeyCode.E)) { Ray ray = Camera.main.ScreenPointToRay(new Vector3(Screen.width / 2, Screen.height / 2, 0)); RaycastHit hit; if (Physics.Raycast(ray, out hit)) { /* * Debug.Log ("Name = " + hit.collider.name); * Debug.Log ("Tag = " + hit.collider.tag); * Debug.Log ("Hit Point = " + hit.point); * Debug.Log ("Object position = " + hit.collider.gameObject.transform.position); * Debug.Log ("--------------"); */ if (hit.collider.tag == "torch" && hit.distance < 6) { Destroy(hit.collider.gameObject); GameObject[] torches = GameObject.FindGameObjectsWithTag("flashlight"); //GameObject torch= GameObject.FindGameObjectWithTag("flashlight"); if (torches != null) { foreach (GameObject torch in torches) { Light light = torch.GetComponent <Light>(); light.enabled = !light.enabled; } // Light light = torch.GetComponent<Light>(); // Light light2 = light.GetComponent<Light>(); // light.enabled = !light.enabled; // light2.enabled = !light2.enabled; } } if (hit.collider.tag.Equals("door")) { door door = hit.collider.gameObject.GetComponent <door>(); door.OpenClose(); } if (hit.collider.tag.Equals("pillow") && hit.distance < 6) { controller.changeScene(); } if (hit.collider.tag.Equals("pillow2") && hit.distance < 6) { controller2.changeScene(); } /* * >>>>>>> bc478438df0cf479507b8d3515e93010d6e5bed2 * if(hit.collider.tag.Equals("switch") && hit.distance < range){ * * InteractiveLight light = hit.collider.gameObject. * LightSwitch light = hit.collider.gameObject.GetComponent<LightSwitch>(); * light.clicked(); * * } */ if (interactive(hit.collider.tag) && hit.distance < range) { GameObject obj = hit.collider.gameObject; InteractiveBehaviour ib = obj.GetComponent <InteractiveBehaviour>(); InventoryGUI.SetInteractiveDisplay(ib.interactiveDescription, ib.timeToDisplay); Debug.Log("inteact"); ib.exec(); } if (pickupable(hit.collider.tag) && hit.distance < range) { GameObject obj = hit.collider.gameObject; ItemBehaviour item = obj.GetComponent <ItemBehaviour>(); // Attempt to pick up item. If successful, remove item from game world. // Play pick-up sound. if (InventoryGUI.hasSpace()) { InventoryGUI.addItem(item); AudioSource.PlayClipAtPoint(pickupSound, Camera.main.transform.position); Destroy(obj); } } } } }