• 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 alphajayel · Mar 30, 2012 at 07:04 PM · onmousedown

Expected Overlapping

First of all, I am not a coder or a programmer, im more of a 3d artist.

I wasnt really sure whether i was doing things right but i got some stuff working. I had to make an interactive portfolio as a requirement before I graduate, and I used Unity to make mine.

I created dock like panel where you can mouse over a thumbnail and when you click it, an animation triggers. This script is assigned to all the buttons and i manually linked the corresponding gameobject in the inspector per Image. So if example, I clicked thumbnail one, var Target plays the animation, and on the next mousedown it plays another animation that represents deactivation of the button.

So the problem is that, when i click Button1, i have to make sure i click it again to mark it "off". Otherwise, if i click Button2 without re-clicking button 1, the animation overlaps.

im having a hard time explaining this, but basically what i want is that to know how i can prevent the overlapping.

Say i click button 1 once, and click a diff button, the script would know that its a diff button so it should "forget" to wait for the 2nd click and move on with the other buttons. and of course that should apply for all the next buttons...

Ugh, i hope it made sense! Im sorry for such a long post. But Thanks to All! :D

here is the script that i used


var Target : GameObject;

var Image : GameObject;

private var clicked : int = 0;

var enter : AudioClip;

var down : AudioClip;

function Start()

{

 renderer.enabled = false;

 Image.gameObject.transform.localScale.x = 0;

 Image.gameObject.transform.localScale.y = 0;

 Image.gameObject.transform.localScale.z = 0;

}

function OnMouseDown()

{

 Image.animation.Play ("ScaleUP");

 if(clicked == 0){

 Target.animation.Play ("Arm Enter");

 clicked = 1;

 }else if(clicked == 1){

 Target.animation.Play ("Arm Exit");

 Image.animation.Play ("ScaleDown");

 clicked = 0;

 }

 if(audio.isPlaying)

 {

 audio.Stop();

   } else 

{

audio.PlayOneShot(down);

}

}

function OnMouseEnter()

{

 renderer.material.SetColor ("_Color", Color.white);

 renderer.enabled = true;

 Target.renderer.material.SetColor("_Color", Color.white);

  audio.PlayOneShot(enter); 

}

function OnMouseExit()

{

 renderer.enabled = false;

 renderer.material.SetColor ("_Color", Color.grey);

 //yield WaitForSeconds(10);

 //clicked = 0; 

}

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

0 Replies

· Add your reply
  • Sort: 

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

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Passing OnMouseDown to other Colliders 2 Answers

OnMouseDown() intended behaviour 1 Answer

Why is OnMouseDown only working if i click outside of unity then click the object? 0 Answers

It seems to me that if I click on a GUITexture the click event is captured not only by the texture but also by the object behind it 2 Answers

How can I prevent an invisible collider from intercepting an OnMouseDown() event? 2 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