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 Matthew Dennis · Apr 18, 2011 at 03:05 PM · collisiontriggermouse

Question about mouse events with box collider triggers

Hello,

Is it possible for a "OnMouseUp()" to be only used once?

Here is an explanation of this question. Picture a scenario where you are flowing through a menu system (Main menu, World Select, Level Select). Now the buttons for each screen are;

(Main Menu = Play Game) (World Select = World 1 - 4) (level Select = Level 1 - 5, Back Button)

Now my problem here is that, i can function the whole menu system to where i can navigate all the way through to being able to click the back button to go back to the world select. Only problem is, when i attempt to click World 1 again, it does not want to do anything.

I have the button to be a 3D text, with a box collider around it. This is a trigger so i can click the button. Below is my sample code;

var tm : TextMesh;

var tmtwo : TextMesh; var tmthree : TextMesh; var tmfour : TextMesh;

static var pressed = false;

function OnMouseEnter() { if(pressed == false) { renderer.material.color = Color.red;
} else if(pressed == true) { renderer.material.color = Color.blue;
} //renderer.material.color = Color.green; }

function OnMouseExit() { renderer.material.color = Color.white; }

function Update () {

if(worldone.drawit == true) { tm.GetComponent(TextMesh).text = "World One"; tmtwo.GetComponent(TextMesh).text = "World Two"; tmthree.GetComponent(TextMesh).text = "World Three"; tmfour.GetComponent(TextMesh).text = "World Four";

 tm.renderer.enabled = true;
 tmtwo.renderer.enabled = true;
 tmthree.renderer.enabled = true; 
 tmfour.renderer.enabled = true;

} else if(worldone.drawit == false) { tm.renderer.enabled = false; tmtwo.renderer.enabled = false; tmthree.renderer.enabled = false; tmfour.renderer.enabled = false; } / if(backbutton.pressed == true) { pressed = false;
}
/

}

function OnMouseUp() { pressed = true; renderer.material.color = Color.green;

if(backbutton.pressed == true)
{
    tm.renderer.enabled = true;
    tmtwo.renderer.enabled = true;
    tmthree.renderer.enabled = true;
    tmfour.renderer.enabled = true;
}

}

To explain more about my code; tm is represented to the 3D Text i am trying to click. It has a box collider on it and is ticked as a trigger (so are, tmtwo, three and four). Pressed is the boolean i use to state if i have clicked the button or not.

The OnMouseEnter; For testing purposes i am changing the color to see what state the boolean is in.

The Update; Worldone is another JS file where when an action not explained in this question(it is irrelevant) is hitting a collider to make the texts "World one - four" appear on screen. As shown by the true statement.

When that said irrelevant action is not in that collider, the text is not to be shown.

The OnMouseUp; When the button is pressed, it changes the boolean to be true so that the text gets removed and it will move into the level select screen.

The JS file for the "Worldone" and "backbutton" can be shown below.

Backbutton

var tm : TextMesh;

static var pressed = false;

function OnMouseEnter() { renderer.material.color = Color.green; }

function OnMouseExit() { renderer.material.color = Color.white; }

function OnMouseUp() { pressed = true; }

function Update() { if(worldselect.pressed == true) { tm.GetComponent(TextMesh).text = "Back"; } if(pressed == true) { tm.renderer.enabled = false; } }

Worldone

var triggerhit = false; static var drawit = false;

function OnTriggerEnter() { triggerhit = true; }

function OnTriggerExit() { triggerhit = false; } function OnGUI() { if(triggerhit == true) { drawit = true; } if(triggerhit == false) { drawit = false; } }

Hopefully i have explained the problem well, if not i will comment more

This problem maybe the way i have structured my code or my logic is wrong, either way i have spent a few hours today on this problem and i need another pair of eyes to see it :)

Thank you Matthew Dennis

Comment
Add comment · Show 1
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 Matthew Dennis · Apr 18, 2011 at 03:07 PM 0
Share

i'm not sure why the code clamp didnt work for most of this.

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.

Follow this Question

Answers Answers and Comments

No one has followed this question yet.

Related Questions

2D Rigidbody Drag with Mouse 0 Answers

RigidBody - GameObject moves but mesh stays! 1 Answer

Inverse 2D Collider, is this possible? 0 Answers

Best practice for OnTriggerEnter detection 1 Answer

Performance: How expensive are Trigger Collisions? How many collision layers should be used? 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