- Home /
Unity Scripts is disabled
I'm new in using unity and i have a problem that when i add new script to an object after loading it will be disabled and when i edit it i can't access functions inside rigidbody like add torque
We can't help you with your code if we can't see it. What do you mean by 'can't access functions' ? Nothing happens when you call it or do you get an error so you can't run the game?
In edit mode make sure your scripts and objects are enabled. Save scene, save project.
@Nose$$anonymous$$ills Thanks for helping me. when i'm trying to write code rigidbody. it should give me list of function like addtorque,addRelativeTorque but I cannot see any function in the list I have attached an image of what I think it is the problem the script is not enabled.
Its really not clear what your problem is.
Click the triangle to open the Rigidbody box. The things you mention wont appear in editor.
Are you talking about the AutoComplete in $$anonymous$$ono/VS??
Private members wont appear in editor by default.
Answer by Bunny83 · Feb 17, 2016 at 05:25 PM
I'm with meat5000. From the question and comments it seems the problem you have is related to scripting in VisualStudio / MonoDevelop. However it's not clear what the problem actually is. Also the enabled state of a script inside the Unity editor has absolutely no influence on VisualStudio / MonoDevelop. Besides that your script component is enabled since the checkbox is checked.
A Rigidbody component actually can't be disabled at all, that's why it doesn't have a checkbox inside the editor. All components can be "collapsed" / "expanded" by clicking the small triangle at the top left. However that's just a pure visualization setting in the editor. It has no influence on the functionality of a component if it's expanded or collapsed in the inspector.
trying to write code rigidbody
If you mean that you want to access the rigidbody component in your script, you have to use GetComponent<Rigidbody>()
. In the past there was the rigidbody
shortcut property which however has been deprecated and is no longer available. If you need access to the Rigidbody component you should add a variable to your script and initialize it in the Awake method:
// C#
Rigidbody rb;
void Awake()
{
rb = GetComponent<Rigidbody>();
}
// UnityScript
var rb : Rigidbody;
function Awake()
{
rb = GetComponent(Rigidbody);
}
Now you can use rb.XXX
inside this script where XXX can be any instance member of the Rigidbody component. Things like rb.AddTorque(torque);
Next time if you have a scripting problem you should add more details on your actual problem. The actual code your using would be a good hint. Maybe you placed your code at the wrong place inside your script?
If this doesn't help you, you should consider to edit your question and clarify your problem because questions here on UA should be detailed and specific as well as clear and simple
Your answer
Follow this Question
Related Questions
I'm trying to set a script to inactive 1 Answer
Why RaycastHit.triangleIndex return -1 ? 1 Answer
How can i change a button text from "Button" to example "Button1" ? 1 Answer
MissingReferenceException Problem 0 Answers
How can i set transform.position on y ? And why i'm getting error cannot convert double to float ? 3 Answers