Zoom In: Reveal hidden object - help

I know I'm somewhere close to where I wanna be with what I'm trying to do, but I'm a little bit clueless on what needs to be done next.

My HideShow.js toggles visibilty of the gameobject + children with every click. However, I need it to be just on when the parent of that gameobject is selected and the zoomedIn = true (in CameraMover.js).

I'm pretty sure I need to call HideShow back into the CamerMover script, but maybe add something else?

Any help would be wonderful.

Hierarchy:

00-Script

Table 5 > 118 > Element > children

HideShow.js -- attached to Element

    var zoomedIn = false;

function Update() {
    if (zoomedIn){
        if (Input.GetMouseButtonDown(0)) {
            ToggleVisibility();
        }
    }
}

function ToggleVisibility() {
// toggles the visibility of this gameobject and all it's children
    var renderers = gameObject.GetComponentsInChildren(Renderer);
    for (var r : Renderer in renderers) {
        r.enabled = !r.enabled;
    }
}

//GameObject.Find("00-Script").GetComponent(CameraMover).zoomedIn;

CameraMover.js -- attached to 00-Script

        #pragma strict

    var myCamera : Transform;
    var targetPosition : Vector3;
    var zoomedIn : boolean;
    var defaultPosition : Vector3;
    var camOffset : Vector3;
    var mouseOver : String;
    var mouseStillOver : String;

    function Start(){
        targetPosition = myCamera.position;
    }

    function Update () {
        if(mouseStillOver==""){
            if(Input.GetMouseButtonDown(0)){
                if(zoomedIn){
                    targetPosition = defaultPosition;
                    zoomedIn = false;
                }        
                else{
                    var ray : Ray = Camera.main.ScreenPointToRay (Input.mousePosition);
                    var hit : RaycastHit;
                    if (Physics.Raycast (ray,hit, 50)) {
                        //targetPosition = hit.point;
                        var hitPosition = hit.transform.position;
                        targetPosition = hitPosition+camOffset;
                        zoomedIn =true;
                    }        
                }    
            }
        }

        //Get GUI Tooltip and hold for "click-through" prevention
        if(mouseOver==""){Invoke("ClearMouse",.15);}
        else{mouseStillOver = mouseOver;}

    myCamera.position += 0.25*(targetPosition-myCamera.position);
}

//Get GUI Tooltip and hold for "click-through" prevention
function ClearMouse(){
    mouseStillOver = mouseOver;
}

Not sure what you want to do here, but the variable zoomedIn in CameraMover has nothing to do with the one in HideShow so setting it in CameraMover won't have any effect for HideShow. Also it seems as if your logic relies on the condition, that CameraMover.Update() will be executed before HideShow.Update(), which is a bad idea, as there is no guarantee this will work.

If you could describe in more detail what you want to do I’m sure we can come up with a simple solution. :wink:

I tried to combine the two scripts; however, I'm not sure I'm going the right direction. Would it be possible do something with camera position to get it to work?

I know this is an old post but let me add something to that. You can easily overcome this problem with a simple addition.

In your zoom camera script, which is something like this in js.

function Update () {

if (Input.GetButtonDown(“Fire2”))

{
camera.fieldOfView = 26;

}
else if (Input.GetButtonUp(“Fire2”))

{
camera.fieldOfView = 66;

}

}

You can change the numbers from 26/66 to your desire, you will add a simple codeline of:

camera.farClipPlane = 500

and a

camera.farClipPlane = 1000, so when you zoom your camera’s far field increases and you can see otherwise hidden objects with your camera when you zoom.

You can make any modification on the numbers as you desire to make your game nice. If you want a slow zoom like Halo, this will also work:

private var zoom : boolean = false;

var zoomSpeed : float = 2.5;

function Update() {

if (Input.GetButtonDown(“Fire2”))

{
if(zoom==false){zoom=true;}
else{zoom=false;}

}

if(zoom==false)

{
if(camera.fieldOfView<66)

{
	camera.farClipPlane = 500;
    camera.fieldOfView = Mathf.Clamp(camera.fieldOfView+zoomSpeed,26,66);

}

}

else

{
if(camera.fieldOfView>26)

{
	camera.farClipPlane = 1000;

    camera.fieldOfView = Mathf.Clamp(camera.fieldOfView-zoomSpeed,26,66);

}

}

}