[RPC] void PickUpItem(int x_pos, int y_pos, string who) { if (PhotonNetwork.isMasterClient) { int item_index = -1; Debug.Log("Got request to pick up item at " + x_pos + ", " + y_pos + " from " + who); GCtrller world = GameObject.FindGameObjectWithTag("World").GetComponent <GCtrller>(); if (world) { for (int i = 0; i < world.items_in_game.Count; ++i) { Debug.Log(world.items_in_game[i].name + " at: " + world.items_in_game[i].transform.position.x + ", " + world.items_in_game[i].transform.position.y); if (world.items_in_game[i].transform.position.x == x_pos && world.items_in_game[i].transform.position.y == y_pos && !world.items_in_game[i].GetComponent <Item>().is_picked) { string item_name = world.items_in_game[i].name; world.items_in_game[i].GetComponent <Item>().is_picked = true; Debug.Log("Item available to be picked up"); item_index = i; photonView.RPC("AssignItem", PhotonTargets.AllBuffered, item_name, who); } } PhotonNetwork.Destroy(world.items_in_game[item_index]); world.items_in_game.Remove(world.items_in_game[item_index]); Debug.Log("There are " + world.items_in_game.Count + " items in the game"); } } }
void Start() { GameObject world = GameObject.FindGameObjectWithTag("World"); if (world != null) { while (true) { GCtrller daScript = world.GetComponent <GCtrller>(); if (daScript != null) { GameObject player = daScript.da_player; target = player.transform; break; } else { Debug.Log("No script detected"); } } } }