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 ChrisJoosten · Mar 20, 2014 at 09:27 AM · c#arraylistvalue

C#: Array question, check value

Hi! I got a few floats and I want to be able to check when 1 of them has set a value to it. Like when x1 = 20f; I want to be able to check it. And if so, how to remove that value. I'm not sure how to do this. I thought an array or something but I'm not sure how to check if one has a value.

The floats: v

     private float x1;
     private float x2;
 
     private float y1;
 
     private float z1;
     private float z2;
     private float z3;
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

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by mattyman174 · Mar 20, 2014 at 10:06 AM

 private float[] floatArray = new float[6] {1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f};  //  Define a new float array and give it the name 'floatArray', fill it with some values.
 
 public float x1;
 
 x1 = floatArray[0];  //  Assign the value in the first index of our floatArray to the variable x1;
 
 //  x1 will now equal 1.0f


Alternatively instead of assigning values to the Array in its definition, you can assign values to its indices 1 at a time like so.

 private float[] floatArray = new float[6]; // Define the array.
 
 floatArray[0] = 1.0f; // Assign values one at a time to each index.
 floatArray[1] = 2.0f;
 floatArray[2] = 3.0f;
 floatArray[3] = 4.0f;
 floatArray[4] = 5.0f;
 floatArray[5] = 6.0f;

Keep in mind that Arrays are of fixed length. The 0th index is always the first index in the array.

Comment
Add comment · Show 6 · 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 ChrisJoosten · Mar 20, 2014 at 10:11 AM 0
Share

Yes thanks for your help. $$anonymous$$y goal is that only one of the floats can have a value for example 20, and the rest is put to 0. Hope im making my case clear here :)

avatar image mattyman174 · Mar 20, 2014 at 10:15 AM 1
Share

Just assign 0 to all other floats except the one you want to be different?

Is there a condition in which all other floats are to remain 0 or is this just your preference for the moment?

From the limited information you have given i cannot provide a sufficient answer if your having other difficulties.

Assigning values to your array indicies is as simple as i have outlined above, if you want only a single float to be a value other than 0 refer to below.

     private float[] floatArray = new float[6]; // Define the array.
      
     floatArray[0] = 20.0f; // Assign values one at a time to each index.
     floatArray[1] = 0f;
     floatArray[2] = 0f;
     floatArray[3] = 0f;
     floatArray[4] = 0f;
     floatArray[5] = 0f;
avatar image Bunny83 · Mar 20, 2014 at 10:18 AM 0
Share

@ChrisJoosten: No, it's not really clear what you actually want to do. If only 1 of them is used at a time, why do you actually need the others? A single float variable and an additional int variable would serve the same purpose:

     float theValue = 20.0f;
     int theIndex = 5;

so the 5. "value" is set to 20

avatar image ChrisJoosten · Mar 20, 2014 at 10:19 AM 0
Share

It has to be dynamic.

Im using them to change the rotation from an object. so when i set the value of x1 to 20, the objects rotates/moves to that direction. That's why I only want one float at a time to have a value else the object will be flying randomly through the scene :p

avatar image mattyman174 · Mar 20, 2014 at 10:24 AM 0
Share

There is specific functions designed to help you Rotate Objects.

http://docs.unity3d.com/Documentation/ScriptReference/Transform.Rotate.html

Show more comments

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

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

Related Questions

How to let multiple values contribute two one value constantly 1 Answer

How to properly create a 2 dimensional array of an object. [C#] 1 Answer

Give a name for each class in List/array 2 Answers

Splitting text from lines into variables 0 Answers

Pathfinding through pairs of connections 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