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 maggot · Dec 17, 2011 at 03:08 PM · c#arrayvalue

Assigning value stored in an array with get{} using cSharp

Using cSharp, I am currently assigning the public float value shootForce as such :

 public class Bullet {
 
 public struct bulletData
 {    
     
     private float _shootForce;
     public float shootForce    // The force at which missiles travel 
     {            
         get
         {
             _shootForce = 2f;
             return _shootForce;    
         }
         set{_shootForce = value; }
     }
 }

I'm accessing the value from other classes / scripts such as moveMissiles.cs in this way :

 Bullet B = new Bullet();
 
 void FixedUpdate () 
 {
     rigidbody.velocity = transform.up * B.playerBullet.shootForce;
 }

   

How do I assign the value of shootForce to a value contained within an array defined outside the shootForce property.

Comment
Add comment · Show 6
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 jahroy · Dec 17, 2011 at 11:27 PM 0
Share

Just out of curiosity, what is the advantage of using properties like this?

I see none at all.

(I have a feeling this question demonstrates why I prefer not to use IDEs)

avatar image maggot · Dec 18, 2011 at 07:26 PM 0
Share

what is IDE in this context?

avatar image jahroy · Dec 18, 2011 at 07:46 PM 0
Share

In this context IDE means Visual Studio or $$anonymous$$onoDevelop.

I am curious if the only reason you're using properties is because your IDE encourages it.

avatar image maggot · Dec 18, 2011 at 07:57 PM 0
Share

Yeh, I'm rewriting the code. I have gotten rid of the get{} and set{} from shootForce. Once I have it fully working I'll put up an answer, though of course I may shuffle code around after.

avatar image Bunny83 · Dec 23, 2011 at 01:42 PM 0
Share

If you wrote another question, why did you screw this one up? You edited the question 18 times!!! You totally changed the question and removed the titel. How should that be useful for others when you have answers that were correct for your 4th revision but you just exchanged everything? The edit button is there to improve the question, not to hide the actual question.

If you have another question, ask a new one. If this one is still not answered try to extend the question, but don't change it to something else. I've read comments about properties but there are no properties in your question (at least the last revisions).

That's actually the worst you could do to this site.

Show more comments

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by jahroy · Dec 17, 2011 at 11:22 PM

You would do it just like you would with any other value:

arrayOfFloats[someNumber] = B.playerBullet.shootForce;

The above line of code demonstrates how you would assign the value of some bullet's shootForce to element someNumber of an array named someArray.

If you wanted to set it to the first element of an array named funkyArray you would do it like this:

funkyArray[0] = B.playerBullet.shootForce;

Note that arrays start with element number zero for most programming languages.

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.

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

Store reference to array as variable 2 Answers

How to check if vector in array was not changed? 1 Answer

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 Answers

Assign gameobject value from an array (C#) 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