Change orbit targert

I am working on a 3d teaching project (not a gamer… sorry) in which I am using the following script to have the main camera orbiting around an object:

using UnityEngine;
using System.Collections;

public class OrbitObject : MonoBehaviour {

		
	public Transform target;
	public float distance= 5.0f;
	public float yMinLimit = -180f;
	public float yMaxLimit = 180f;
	public float FOVMin = 10;
	public float FOVMax = 60;
	public float smoothTime = 1f;
 		
	float rotationYAxis = 0.0f;
	float rotationXAxis = 0.0f;
	float velocityX = 0.0f;
	float velocityY = 0.0f;//On_Swipe
		//end of added
	
	// Subscribe to events
	void OnEnable(){
		EasyTouch.On_PinchIn += On_PinchIn;		
		EasyTouch.On_PinchOut += On_PinchOut;
		EasyTouch.On_Swipe += On_Swipe;
	}
	
	void OnDisable(){
		UnsubscribeEvent();
	}
	
	void OnDestroy(){
		UnsubscribeEvent();
	}
	
	// Unsubscribe to events
	void UnsubscribeEvent(){
		EasyTouch.On_PinchIn += On_PinchIn;
		EasyTouch.On_PinchOut += On_PinchOut;
		EasyTouch.On_Swipe -= On_Swipe;	
	}
		
	void Start(){
	 	Vector3 angles = transform.eulerAngles;
        rotationYAxis = angles.y;
        rotationXAxis = angles.x;

        // Make the rigid body not change rotation
        if (rigidbody)
        {
            rigidbody.freezeRotation = true;
        }
	}
		
	// Zoom in and zoom out with pinch
	void On_PinchIn(Gesture gesture){
		float zoom = Time.deltaTime * gesture.deltaPinch*5;
		Camera.mainCamera.fieldOfView=Mathf.Clamp((Camera.mainCamera.fieldOfView+=zoom), FOVMin, FOVMax);
		
	}
	
	void On_PinchOut(Gesture gesture){
		float zoom = Time.deltaTime * gesture.deltaPinch*5;
		Camera.mainCamera.fieldOfView=Mathf.Clamp((Camera.mainCamera.fieldOfView-=zoom), FOVMin, FOVMax);
			
	}
	
	//Swipe
	void On_Swipe( Gesture gesture){
		//Only if it is a single finger
		if (gesture.touchCount==1 ){
			rotationXAxis -= gesture.deltaPosition.y;//inverted after result on tablet
			rotationYAxis += gesture.deltaPosition.x;//inverted after result on tablet		
			rotationXAxis = ClampAngle(rotationXAxis, yMinLimit, yMaxLimit);
			Quaternion toRotation = Quaternion.Euler(rotationXAxis, rotationYAxis, 0);
	        Quaternion rotation = toRotation;
	        Vector3 negDistance = new Vector3(0.0f, 0.0f, -distance);
	        Vector3 position = rotation * negDistance + target.position;
			transform.rotation = rotation;
			transform.position = position;
			velocityX = Mathf.Lerp(velocityX, 0, Time.deltaTime * smoothTime);
			velocityY = Mathf.Lerp(velocityY, 0, Time.deltaTime * smoothTime);
		}
	}

 	void LateUpdate()
    {
		//Allows mouse scrollwheel to control zoom as the mouse already controls the rest	
		if (Input.GetKeyDown(KeyCode.Escape)) { Application.Quit(); 
		}
		float zoom = Time.deltaTime * Input.GetAxis("Mouse ScrollWheel")*2000;
		Camera.mainCamera.fieldOfView=Mathf.Clamp((Camera.mainCamera.fieldOfView-=zoom), FOVMin, FOVMax);
		
	}

    public static float ClampAngle(float angle, float min, float max)
    {
        if (angle < -360F)
            angle += 360F;
        if (angle > 360F)
            angle -= 360F;
        return Mathf.Clamp(angle, min, max);
}
}

This script uses the Easy Touch plugin and it works well with tablets.
However, I need to change the target while running, using a GUI.
I basically have a number of objects that I need to make visible or invisible as the user selects the target (it is an anatomy course).
I have been reading about GetComponent but I am lost! Can someone shed light as I am a newbie?
Thanks in advance

If I am understanding you correctly; you have a number of objects in the scene and you want to change the object that you can target; hiding all objects other than the targeted object and then the camera rotates around the selected object?

In simplistic terms; you can use GetComponent to find and reference an object in the scene; so lets say you have three objects in the scene; you use can use GetComponent in order to create a reference (or handle) for that object and then use that handle to interact with that object in some way; or to access methods attached to any scripts applied to that object.

If thats what you mean; this might help (note I am coding on the fly so totally untested):

GameObject theObject = GameObject.Find("theObjectToFind");

That will look up the GameObject named “theObjectToFind” and give it a reference variable of “theObject”.

In other words, creating a variable called theObject (which is your handle to the object) as a GameObject data type and then using GameObject.Find to find the specific object in the scene.

If you need to call any methods (functions) within any classes (scripts) that are attached to the object, you need to create a reference to the class script that is applied to the object. Something like this:

theClassName theObjectClassRef = (theClassName) theObject.GetComponent(typeof(theClassName));

Here we are creating a variable called “theObjectClassRef” it’s type is set to the name of the class that is attached to the object. We are then setting this reference variable to the the class using GetComponent().

GetComponent actually returns a component that is attached to an object rather than the object itself. i.e. the object in the scene is a GameObject; thus is found using “Find”; to create a reference in a GameObject variable and a script that is attached to the object is a “Component” of the object; thus you use GetComponent to return a handle to that particular object.

Lets say you have a hand object in the scene, with a script attached to it called “handController.cs” which has a method called “moveIndexFinger()” which moves the index finger.

You could do this:

GameObject handObject = GameObject.Find("hand");
handClass handController = (handClass) hand.GetComponent(typeof(handClass));

handController.moveIndexFinger();

You can also call upon any variables within the class attached to the object (like the transform of the object which you could use to change the cameras attachment).

So if I am reading your post right; you could create a reference to each object in the scene:

GameObject handObject = GameObject.Find("hand");
GameObject armObject = GameObject.Find("arm");
GameObject bodyObject = GameObject.Find("body");

Each of these objects could have a script attached to them which provides any methods or variables that are relevant to the object (i.e. the transform of the object itself) then when the player selects and object; you set the camera target to the transform of the selected object and move it into place (or have a separate camera for each object and change cameras).

Does that make sense? I may have gotten a bit wooly there.