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 koriley · Apr 07, 2015 at 04:17 AM · unity5components

enabling components

Everything I have read, has said that to enable a component from a script on an object all I need to do is: GetComponent ().enabled = true;

FirstPersonController is a script, that is on a component of my 'player'.

I have it disabled with the idea of enabling it on multiplayer, so the server does not control all of the players.

I have read in the manual and api, watched videos and read countless forums, and it always comes back to the string listed above.

I;m using unity 5, has the api changed for this drastically?

I have also tried creating a pulic var as it kinda says on this page: http://docs.unity3d.com/ScriptReference/Component.GetComponent.html

so can any of you shed some light on this for me please? any suggestions of something to try next?

Thanks, Kevin

 void Update()
     {
         nView = GetComponent<NetworkView>();
 
         if (nView.isMine)
         {
             rigidbody.useGravity = true;
             GetComponent<FirstPersonController> ().enabled = true;
             
             foreach(Camera cam in GetComponentsInChildren<Camera>())
                 cam.enabled = true;
         }
 
     }

I have also tried:

 private NetworkView nView;
 public Rigidbody rigidbody;
 // these are on the code snip above too
 
 private FirstPersonController fpc;
 void Update()
     {
         nView = GetComponent<NetworkView>();
                 fpc = GetComponent<FirstPersonController> ()
         if (nView.isMine)
         {
             rigidbody.useGravity = true;
             fpc.enabled = true;
             
             foreach(Camera cam in GetComponentsInChildren<Camera>())
                 cam.enabled = true;
         }
 
     }


The reason I ask if it has changed drastically is because, every code snip I try, even the ones from unity3d.com/learn seem to have problems with 5. I can copy and paste them to 4.6 and they work fine, but with 5 I seem to always have to manipulate them to work. So I guess the drastically was more afraid there have been changes but the documentation isn't reflecting current api across the board.

@gjf thanks for pointing out my post was incomplete. I have edited per your suggestions.

Comment
Add comment · Show 2
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 gjf · Apr 06, 2015 at 10:31 AM 1
Share

the api has not changed drastically.

in order to help you, we'll need to see the code that you've tried...

...and make sure that you format it correctly. check our the tutorial video/faq if you're not sure.

avatar image koriley · Apr 07, 2015 at 04:10 AM 0
Share

figured it out.. close this.. unless you want me to give what I learned

0 Replies

· Add your reply
  • Sort: 

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

2 People are following this question.

avatar image avatar image

Related Questions

How the heck can I include Lightmapping data in unity 5 asset bundles??? 3 Answers

Unity5 5.0.0p3 build: Failed to initialize player's 3D settings 0 Answers

Is there a way to open a .unity3d file in the editor? 1 Answer

Random.Range always returns the minimum value 1 Answer

Marmoset + Unity 4 vs Unity 5 Lighting 0 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