void Update() { Ray ray = cameraObject.ScreenPointToRay(Input.mousePosition); if (Physics.Raycast(ray, out hit)) { // the object identified by hit.transform was clicked string[] display = hit.transform.ToString().Split(new string[] { "(" }, System.StringSplitOptions.RemoveEmptyEntries); upperLeftCornerText.text = (display[0] + " : "); } if (Input.GetMouseButtonDown(1)) { selected = GameObject.Find(hit.collider.gameObject.name); //hit.transform.gameObject parent = selected.transform.parent.name.ToString(); if (parent == "npc") { npc = selected.GetComponent <npc_script>(); } if (parent == "item") { item = selected.GetComponent <item_script>(); } if (parent == "container") { container = selected.GetComponent <container_script>(); } position = Input.mousePosition; onContextMenu = true; } if (Input.GetMouseButtonUp(1)) { onContextMenu = false; onPlayerPhysicalInventory = false; onDialogLaunch = false; onContainerOpen = false; onInventoryItem = false; onContainerItem = false; selected = null; } }
// Use this for initialization void Start() { //Debug.Log("Event script for room P initialized!"); player = GameObject.FindObjectOfType(typeof(player_script)) as player_script; npc = GameObject.FindObjectOfType(typeof(npc_script)) as npc_script; npc_object = GameObject.FindWithTag("NPC"); NPC2 = GameObject.FindWithTag("NPC2").GetComponentInChildren(typeof(SpriteRenderer)) as SpriteRenderer; walking = npc_object.GetComponentInChildren(typeof(Animator)) as Animator; idle = npc_object.GetComponentInChildren(typeof(SpriteRenderer)) as SpriteRenderer; dialogManager = GameObject.FindObjectOfType(typeof(dialog_script)) as dialog_script; event1 = GameObject.FindWithTag("Entry_P").GetComponent <ColliderListener> (); playerCameraObject = GameObject.FindWithTag("MainCamera"); npcCameraObject = GameObject.FindWithTag("Camera3"); playerCamera = playerCameraObject.GetComponent <Camera> (); npcCamera = npcCameraObject.GetComponent <Camera> (); npcSprite = npc_object.GetComponentInChildren(typeof(SpriteRenderer)) as SpriteRenderer; npcAnimation = npc_object.GetComponentInChildren(typeof(Animator)) as Animator; }