• 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.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



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

Top down movement and rotation 2 Answers

Erratic movement problem 2 Answers

Runescape Movement and camera rotation 2 Answers

Mouse Follow Script Help 1 Answer

How to select one prefab from more ? 0 Answers

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges