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 /
This question was closed Jul 17, 2014 at 04:26 PM by Graham-Dunnett for the following reason:

Duplicate Question

avatar image
0
Question by Trilby · Dec 17, 2013 at 05:29 PM · disableenablecs0246cs0119

CS0119 Error for Script Disable?

Hello, I've been working on a script to disable a script in one scene, but to keep it enabled on another. However, I've been getting an error which I thought was to do with constructors, not scripts. I've tried adding new in front of GetComponent, but that ended up giving a CS0246 error instead.

 using UnityEngine;
 using System.Collections;
 
 public class Reset : MonoBehaviour
 {
     public Alive alive;
     
     void Start()
     {
         alive = GetComponent(Alive);
     }
     
     void Update()
     {
     if (Input.GetKeyDown("z"))
         {
             alive.enabled = true;
             Application.LoadLevel(1);
         }
     
     if (Input.GetKeyDown("x"))
         {
             alive.enabled = false;
             Application.LoadLevel(0);
         }
     }
 }

The error is:

 Assets/Reset.cs(10,38): error CS0119: Expression denotes a `type', where a `variable', `value' or `method group' was expected
Comment
Comments Locked · Show 1
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 robertbu · Dec 17, 2013 at 05:57 PM 0
Share

You can use the Generic version:

 alive = GetComponent<Alive>();

1 Reply

  • Sort: 
avatar image
0
Best Answer

Answer by guitarxe · Dec 17, 2013 at 05:46 PM

Need different syntax for C#

 alive = GetComponent<Alive>();

Might need to still cast it as Alive

This question has example of GetComponent in C# http://answers.unity3d.com/questions/550578/cant-understand-getcomponent-c.html

Comment
Comments Locked · 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 Trilby · Dec 17, 2013 at 05:55 PM 0
Share

I just tried that, I still get a CS0119 error.

avatar image guitarxe · Dec 17, 2013 at 06:01 PM 0
Share

Oh hold on, C# uses a different syntax for this. I'll edit the answer.

avatar image Trilby · Dec 18, 2013 at 06:01 PM 0
Share

$$anonymous$$anaged to get the issue resolved in the end after a bit more digging, I should have probably mentioned I'm doing this in v2.5.

And now I've run right into another issue, namely that Alive is an Awake function (DontDestroyOnLoad, to be precise). But that's a result of my own ignorance, not your script, so I guess this is solved. Hopefully its useful for others at least. I'll probably try to use an If statement in the Awake function ins$$anonymous$$d, using Application.loadedLevel.

Follow this Question

Answers Answers and Comments

17 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

Related Questions

Enable/Disable GameObject Button script 1 Answer

Unable to enable script 0 Answers

Re Enable C# script on camera 1 Answer

Disabled Script still does OnMouseDown 1 Answer

I need to find a Script and Disable/enable it.. 1 Answer


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