- Home /
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.
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.
figured it out.. close this.. unless you want me to give what I learned
Your answer
![](https://koobas.hobune.stream/wayback/20220613192305im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
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