Jump to content
This site uses cookies! Learn More

This site uses cookies!

armedunity.com uses cookies to improve user experience.

By continuing to use this site, you agree to allow us to store cookies on your computer.

  • 0
Sign in to follow this  
gonzalitosk8

Enable/Disable script in c#?

Question

how to enable and disable scripts with another script? (c#)

 

script:

 

using UnityEngine;
using System.Collections;
 
public class nitro : MonoBehaviour {
 
public Component N20;
public Component Setup;
 
void Start(){
    N20 = GetComponent<N20>();
Setup = GetComponent<Setup>();
}
 
void Update(){
    if(Input.GetButtonDown("nitro")){ 
    N20.enable = true;
Setup.enable = false;
}
else
{
if(Input.GetButtonUp("nitro")){ 
    N20.enable = false;
Setup.enable = true;
    }
   }
  }
 }
 

 

Message error on unity:

nitro.cs(16,9): error CS1061: Type `UnityEngine.Component' does not contain a definition for `enable' and no extension method `enable' of type `UnityEngine.Component' could be found (are you missing a using directive or an assembly reference?)

 

help me please!

 

Share this post


Link to post
Share on other sites

3 answers to this question

Recommended Posts

  • 0

There are many questions about this on the internet. Just search it on google, its that simple

Share this post


Link to post
Share on other sites

  • 0
Please login or register to see this quote.

search the internet, but only find results like this: enable / disable script from js .. if I had found it, I would not ask .. know it? I explain it?

Share this post


Link to post
Share on other sites
  • 0

Always make sure you check to make sure your syntax is correct and nothing is misspelled or missing. For instance, as a suggestion, when declaring a component variable, instead of declaring as a general component, declare it as the component name. public N20 n20;

But as for your error message, you didn't type in the function name correctly. It's enabled, not enable.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

×
×
  • Create New...