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 casperskyly · Oct 14, 2014 at 06:29 PM · javascriptfloatlinklinkingsame

linking floats

I need two floats to be linked, so when I change one, the other changes with it. This needs to be able to go either way.

For example:

 var example1 : float;
 var example2 : float;
         
 function Update ()
 {
    example1 = example2;
    example2 = example1;
 }

If I change example2, example1 changes with it, but if I try to change example1, it doesn't work.

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 tanoshimi · Oct 14, 2014 at 06:30 PM 2
Share

Ummm.... why?

avatar image richyrich · Oct 14, 2014 at 06:53 PM 0
Share

Also with tamoshimi, but just for fun... ;)

         void Start ()
         {
             float x = 10;
             refs(ref x, ref x);
         }
     
         void refs(ref float X, ref float y)
         {
             X = 10;
             y = 11;
             Debug.Log("x: " + X);//outputs 11
             X = 12;
             Debug.Log("y: " + y);//outputs 12
         }
 
avatar image casperskyly · Oct 14, 2014 at 07:00 PM 0
Share

Why? In my settings you can choose whether the sensitivity of the mouse axes are to be seperate, if not, I would like to be able to keep the same gui and mechanics, but have them stay the same.

2 Replies

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

Answer by KayelGee · Oct 15, 2014 at 08:25 AM

I don't know how you set your variables right now but I'll just guess you're using some kind of slider and a checkbox which sets a boolean. If you're set up like this then it's pretty straightforward.

 var keep_values_same : bool;
 var axis_x : float;
 var axis_y : float;
 
 function set_axis_x(new_value: float){
     axis_x = new_value;
     if(keep_values_same) axis_y = axis_x;
 }
 
 function set_axis_y(new_value: float){
     axis_y = new_value;
     if(keep_values_same) axis_x = axis_y;
 }

Instead of changing the values of axis_x and axis_y directly you'll now have to call set_axis_x and set_axis_y instead. This'll make sure the other value changes aswell if your keep_values_same boolen is set to true.

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
avatar image
3

Answer by KpjComp · Oct 14, 2014 at 06:49 PM

I'm with tamoshimi, why?.. but if you still wanted too you could use property setter / getters..

eg.

 private int _example1and2 = 1;
 private int example1 { get { return _example1and2; } set { _example1and2 = value; } }
 private int example2 { get { return _example1and2; } set { _example1and2 = value; } }
 
 //both example 1 & 2 = 1
 
 example1 = 4;
 
 //both example 1 & 2 = 4
 
 example2 = 7;
 
 //both example 1 & 2 = 7
Comment
Add comment · Show 1 · 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 Kiwasi · Oct 15, 2014 at 08:27 AM 0
Share

Its worth noting that properties are full blown methods. So this solution could easily extend out for your use case.

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Operator cannot be used with left hand side of type.... 1 Answer

Where can I submit a unity designed website 0 Answers

Deep Linking to specific Scene in Android build 0 Answers

Error: "ArgumentException: get_deltaTime can only be called from the main thread" 1 Answer

Open link in new tab from webplayer hosted on any site. 3 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