• 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 lenyeto · Aug 08, 2011 at 11:59 PM · javascript

How do i make check if a variable changed

Like, can i make something like this?

 if (A && ~A) {}

with ~A as being if A has changed. I see this in Garry's Mod E2 and its useful, but i don't know how to use something like this in Unity JScript.

Comment
Add comment · Show 3
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 Waz · Aug 09, 2011 at 12:11 AM 0
Share

Changed since when? Last frame? Last time that line of code was executed?

avatar image lenyeto · Aug 09, 2011 at 12:29 AM 0
Share

Well, i want to have somthing like. if (Players$$anonymous$$ouse1 && Player$$anonymous$$ouse1(Has Changed)) { Use()} basicly, so you cant just hold down mouse1 to use something a lot.

avatar image Fornoreason1000 · Nov 01, 2013 at 03:27 PM 0
Share

make a second, variable B is the storage and A is the actual variable. when A != B the variable has changed

 if(A!= B) {
 //do stuff
 B = A;
 
 }

2 Replies

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

Answer by Waz · Aug 09, 2011 at 12:09 AM

No, there is nothing like that in JavaScript or C# with Unity.

Perhaps the closest you can get is a setter function in C#, but if you explain why you actually want this, there is probably a simpler and more obvious explanation of how to achieve what you want (in particular, what is changing the variable?)

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 lenyeto · Aug 09, 2011 at 12:56 AM 0
Share

Well, i want to have somthing like. if (Players$$anonymous$$ouse1 && Player$$anonymous$$ouse1(Has Changed)) { Use()} basicly, so you cant just hold down mouse1 to use something a lot.

avatar image Waz · Aug 09, 2011 at 11:18 AM 0
Share

That's just the Get$$anonymous$$ouseDown event, so Unity already gives you what you need. In general, I have seen here that it's more effective to ask about the specific issue, and get a general answer, than to try to guess a possible general answer and ask about that.

avatar image
0

Answer by khoramsql2008 · Nov 01, 2013 at 04:17 PM

as Waz said you can identify one Boolean for instance MouseIsDown becomes True when GetMouseDown is called and becomes False when GetMouseUp is called. then you can refer to this variable to judge for you.

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

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

6 People are following this question.

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

Related Questions

script linking 1 Answer

problem at adding script 1 Answer

How do I get my "dashing" animation to work? 1 Answer

How to make a N-S magnet Javascript? 1 Answer

How do I make a sword swing? 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