Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Kitty · Apr 15, 2010 at 08:43 PM · gameobjectzoomvisibility

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; }

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

3 Replies

· Add your reply
  • Sort: 
avatar image
2

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. ;)

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Kitty · Apr 16, 2010 at 01:49 PM 0
Share

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.

avatar image StephanK · Apr 16, 2010 at 03:09 PM 0
Share

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?

avatar image
0

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?

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

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);
 
 }

}

}

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

1 Person is following this question.

avatar image

Related Questions

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

Show and Hide a prefab or GameObject 10 Answers

How to make an gameObject invisible and disappeared 8 Answers

C# Rotate GameObjects Regardless of List Size 2 Answers

Array Help GameObject Length Inventory 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges