/// <summary> /// Called when any object located inside the environment is selected. /// </summary> /// <param name="type">the type of object clicked</param> /// <param name="name">the formatted name of the clicked object</param> /// <param name="clickedObject">a reference to the actual object</param> public void ObjectClicked(string type, string name, EnvironmentObject clickedObject) { // check the status of the application and respond to the environment object respectively. if (status == "Environment") { // locate foot menu and store in temp vec. Used to identify the new position of the fish and the information // popup. Vector3 menuPos = new Vector3(Camera.main.transform.forward.x, 0.5f, Camera.main.transform.forward.z); //GameObject.FindGameObjectWithTag ("FootMenu"); // if the previous type was a fish if (prevType == "Fish") { // update the fish that was clicked previously so that it will continue to wander. /* * if (prevObjectWander && prevObjectAgent) { * prevObjectWander.wandering = true; * prevObjectAgent.speed = 0.5f; * } */ } // if the current type is a fish if (type == "Fish") { // get new fish's information NavWander tempWander = clickedObject.GetComponent <NavWander> (); UnityEngine.AI.NavMeshAgent tempAgent = clickedObject.GetComponent <UnityEngine.AI.NavMeshAgent> (); /* * if (tempAgent && tempWander) { * //stop fish from roaming * tempWander.wandering = false; * * //calculate the new position for the fish (near the player) * Vector3 vec = Camera.main.transform.position + (Camera.main.transform.forward * 2.0f); * vec.y = 0.5f; * * * //set the destination of the fish to the calculated position. * tempAgent.SetDestination(vec); * tempAgent.speed = 1.5f; */ //store the new fish's information into temp storage prevObjectWander = tempWander; prevObjectAgent = tempAgent; prevType = type; } else if (type == "Coral" || type == "Other") { //complete coral specific tasks } // call controller to update and configure with the name and new position. //InformationCanvasController.control.UpdateCanvas (name, menuPos, clickedObject); // -------- X start here -------- // // Cleanup the old fakeObject deleteFakeObject(); // Spawn a copy of the object clicked, and move it to the correct location fakeObject = Instantiate((GameObject)Resources.Load("Prefabs/" + clickedObject.formattedName)); // Shoot me Transform fakeLocation = GameObject.FindGameObjectWithTag("UIModel").transform; //fakeObject.transform.parent = fakeLocation; fakeObject.transform.position = fakeLocation.position; if (fakeObject.GetComponent <UIScale>()) { fakeObject.transform.localScale *= fakeObject.GetComponent <UIScale>().Scale; } // -------- X end here -------- // } else if (status == "FindTheFish") { //call game controller and send through the name of the object clicked. FindTheFishGameController.control.WasClicked(name); } else { // add more: status == "game/SceneHere") { } }