- Home /
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; }
Answer by StephanK · Apr 16, 2010 at 08:16 AM
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. ;)
I know that the scripts are working the correctly the way they are now. The thing I'm trying to fix is getting the HideShow to work only when the camera is zoomed into whichever cube the user clicks on and show the object inside the cube. When they click the box again, the camera zooms out and the object hides again. The HideShow is on 118 different objects, so it'll run better if I could get it to work on just the one that's clicked.... Wasn't sure where exactly to take it to get from the basic part I have now with every click it hides/show the Element and all its children.
Try storing the Transform of the object you zoom in as member of the Camera$$anonymous$$over. Then you can use this Transform to toggle its renderer off when you are zoo$$anonymous$$g out. You could also get rid of the HideShow script and modify the visibility directly from the Camera$$anonymous$$over. Does that make sense?
Answer by Kitty · Apr 23, 2010 at 04:45 PM
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?
Answer by Shealei · Jul 12, 2011 at 01:45 PM
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);
}
}
}
Your answer
Follow this Question
Related Questions
Show and Hide a prefab or GameObject 10 Answers
The name 'Joystick' does not denote a valid type ('not found') 2 Answers
How to make an gameObject invisible and disappeared 8 Answers
Array Help GameObject Length Inventory 1 Answer
How to choose between two diffrent idectical objects by clicking? 3 Answers