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 Randize · Jan 06, 2014 at 06:25 AM · c#instantiateclass

The Same Declaration in Different Classes?

I wanna breakdown my script into shorter portion, for better readability and organized. Not sure if this would affect the performance.

But I have an instance in the LateUpdate() function, specifically rightX = Input.GetAxis("RightStickX"); and other similiar instances that I want to use in different classes.

I know that I could declare and initialize the same instance, also I could use a new instance by declaring it from the other class. I have a feeling that they still consume more memory as I make more classes that use the same instance.

My question is, is there a way to use the same object since the float value that I get here is the same all around? Or should I just use Input.GetAxis() without instantiating it?

P.S. I'm following tutorial, not sure why Input.GetAxis() is instantiated in the first place. Would love to know if there's any use other than, maybe making it easier to type?

Comment
Add comment · Show 5
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 Randize · Jan 06, 2014 at 09:40 AM 0
Share

$$anonymous$$aybe I've misused or still don't quite understand the term yet.

To get on the same page as you are, rightX = Input.GetAxis("RightStickX"); Aren't we getting Input.GetAxis() instantiated with rightX? How do we define an instantiation?

avatar image Randize · Jan 06, 2014 at 10:00 AM 0
Share

So the fact that Input.GetAxis is a static function, rightX still points to the same location. I think this corrected understanding solved my problem simultaneously. Thanks!

avatar image GameVortex · Jan 06, 2014 at 10:04 AM 0
Share

No problem. Glad I could help. =)

Would you $$anonymous$$d me converting this exchange to an answer so you could mark it as correct?

avatar image Randize · Jan 06, 2014 at 10:06 AM 0
Share

No problem.

avatar image GameVortex · Jan 06, 2014 at 10:28 AM 0
Share

There we go, sorry, I could not move your comments.

1 Reply

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

Answer by GameVortex · Jan 06, 2014 at 09:30 AM

I am not sure what you mean with Input.GetAxis getting instantiated. Nothing gets instantiated there, it just gets a float value of the specified axis. You can perfectly fine use Input.GetAxis multiple places. Or you can make your rightX value public and reference it in your other scripts.

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 GameVortex · Jan 06, 2014 at 09:51 AM 0
Share

Instantiation would basically be when we create new objects, like instantiating prefabs or using the New keyword to call constructors. The Input.GetAxis only calls the static function GetAxis in the Input class, which returns a float value. No new objects has been created, we have ins$$anonymous$$d received a value that was stored in the Input class.

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

20 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

Related Questions

OnTriggerEnter() not working 1 Answer

Behind the scenes voodoo w/ Instantiate 2 Answers

Instantiate class from other script but same gameObject 3 Answers

Distribute terrain in zones 3 Answers

C# Utility Class 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