Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 Eowyn27 · Jan 08, 2014 at 06:16 PM · cameramovementmousedouble-click

How do I implement double click feature to move camera back to previous position?

So I have several objects, when I click on one object, the camera zooms in and moves to that object. Then I click on that object and the camera moves to another coordinate where another object is located. However, I would like the user to trace back to the original object and then back to the initial position of the camera. So, I was thinking about implementing a double click to have the camera move back to the original position.

I tried looking for a double click reference and I tried to attach this script to my object. However, nothing happens and I'm not sure why. I even set the camera to main camera.

 using UnityEngine;
 using System.Collections;

 public class DoubleClickBack : MonoBehaviour {
 
 public Camera mainCam;
 
 float doubleClickStart = 0;
 
 void OnMouseUp() {
     
     if ((Time.time - doubleClickStart) < 0.3f) {
         
         this.OnDoubleClick();
         
         doubleClickStart = -1;
         
 }
     else {
         
         doubleClickStart = Time.time;
 }
 }
 
     void OnDoubleClick()
 {
         Debug.Log("Double Clicked!");
     
         mainCam.transform.position = new Vector3(0, 1, -7); 
     
         Camera.main.orthographicSize = 100;
 }
 
 }
Comment
Add comment · Show 4
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 edcarlo · Jan 09, 2014 at 03:58 AM 0
Share

did you place that script into individual objects?

avatar image Eowyn27 · Jan 09, 2014 at 04:08 AM 0
Share

Yeah I did. I attached it the object that needed to be double clicked in order for the camera to move back to the previous position.

Should there be anything on the object besides a basic box collider, animator and the script?

avatar image ziv03 · Jan 14, 2014 at 03:20 PM 0
Share

I'm not exactly sure where your problem is. detecting the double click? moving the camera? is the "Double Clicked!" shown in the console? Cause I don't exactly understand your problem

avatar image Eowyn27 · Jan 14, 2014 at 03:49 PM 0
Share

I figured it out. I didn't call my function. It works now.

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by Eowyn27 · Jan 14, 2014 at 03:19 PM

I figured out what was wrong. I didn't call my function on Update()!

 using UnityEngine;
 using System.Collections;

 public class DoubleClickBack : MonoBehaviour {
 
 public Camera mainCam;
 
 private float doubleClickStart = 0;
 
 private float doubleClickLapseTime = 0.3f;
 
 
 void Update() {
     CheckDoubleClick();
 }
     
 void CheckDoubleClick() 
 {
     
 if(Input.GetMouseButtonUp(0)) {
     
             if ((Time.time - doubleClickStart) < doubleClickLapseTime)
             {
                     this.OnDoubleClick();
                 doubleClickStart = -1;
             }
             else
             {
                 doubleClickStart = Time.time;
                 
             }
         
     }
 }
 
 void OnDoubleClick()
 {
         Debug.Log ("Double Click");
         mainCam.transform.position = new Vector3(-0.13f, 0.87f, -8); 
     
         Camera.main.orthographicSize = 0.4f; 
 
 }
 

}

Needed to call the function.... and I added GetMouseButtonUp() instead of Down().

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

20 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How can I produce the typical FPS mouse steering effect? 2 Answers

Mouse Follow Script Help 1 Answer

Camera Movement issue 1 Answer

Move the camera when the mouse reaches the edges of the screen 1 Answer

Select/Drag/Drop Objects with a mouse 0 Answers


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