Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
This question was closed Aug 20, 2017 at 07:10 PM by tanoshimi for the following reason:

Problem is not reproducible or outdated

avatar image
0
Question by Itsgrain42 · Aug 20, 2017 at 06:02 PM · unity 5errorgetcomponent

Get Component Error

I'm having difficulty with this script. It is made to set a separate script as disabled once the main script is enabled. I've checked the script names, they are all correct.

 using UnityEngine;
 using System.Collections;
 
 public class PowerDown : MonoBehaviour {
 
     public GameObject BotScript;
 
     // Use this for initialization
     void OnEnable () {
         BotScript.GetComponent<BotMovement>().enabled = false;
     }
     
     // Update is called once per frame
     void Update () {
     
     }
 }
 

Please help :/

Comment
Add comment · Show 3
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 Itsgrain42 · Aug 20, 2017 at 06:20 PM 0
Share

The botscript is the object that the script I want to disable is in.

avatar image tanoshimi · Aug 20, 2017 at 07:10 PM 0
Share

When asking for help with an error, you must include the full error message and the line number to which it relates. Otherwise, we're just guessing, and there is never any reason to guess what the problem is when debugging code.

avatar image Itsgrain42 tanoshimi · Aug 20, 2017 at 07:44 PM 0
Share

should I post a new question then?

1 Reply

  • Sort: 
avatar image
0

Answer by Bunny83 · Aug 20, 2017 at 06:52 PM

There is no problem with your code as long as you actually assigned the correct gameobject to the "BotScript" variable. However it would be way better to use a variable of type "BotMovement" instead of "GameObject". That way you don't need the GetComponent at all.

 public BotMovement BotScript;
 void OnEnable () {
     BotScript.enabled = false;
 }

Of course if you change the variable type you have to re-assign your object. This is much safer as it doesn't rely on dynamically looking up if that component exists. You directly reference your target script at edit time.

Comment
Add comment · Show 3 · 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 Itsgrain42 · Aug 20, 2017 at 06:59 PM 0
Share

still getting errors for some reason :/

avatar image Itsgrain42 · Aug 20, 2017 at 07:02 PM 0
Share

unless maybe it is because you can't disable a java script through a c# script? idk.

avatar image Bunny83 Itsgrain42 · Aug 21, 2017 at 01:55 AM 0
Share

Uhm you haven't mentioned that in your question. You also did not mention the actual error. So you talk about a compiler error and not a runtime error?

You should avoid mixing UnityScript (Unity's Javascript) and C#. Both languages are compiled independently. Read this page carefully, especially the bit at the bottom about the compilation phases. Scripts in phase 3 can always access everything from phase 1 but not the other way round.

Follow this Question

Answers Answers and Comments

154 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 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 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 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 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 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 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 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

GetComponent Picking up multiple scripts from differrent objects? 1 Answer

"Error building Player" WebGL build error 2 Answers

How do I check if the gameobject I collided with has a certain script? (C#) 1 Answer

Game Analytics & Facebook sdk android build error 1 Answer

GetThreadContext failed (Unity 5) 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