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 /
avatar image
0
Question by TypeFinalMagic · Sep 23, 2017 at 04:04 AM · scripting problemscript error

Cannot use class in one script but other scripts can

I am currently running into an issue where for some reason I can use a specific class I made in basically all my other scripts except for one and I am trying to understand why I can't use it in that specific script.

Currently I created two empty game objects: GameController and UIController each with there own script (Scripts also share the same name). I am trying to pass the UIController class into GameController script so I can change some UI within the UIController script. However when I try to use UIController, I get a "type or namespace "UIController" cannot be found..." error.

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 
 public class GameController : MonoBehaviour {
 
     private GameObject respawnPoint;
     private UIController uiController; ****Error Here****
     [SerializeField] private int hitpoints = 1;
 ...







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 Positive7 · Sep 23, 2017 at 04:14 AM 1
Share

Does your UIController under any namespace ? Does it called UIController and not UiController ... Does the script name the same as the class name?

avatar image frankslater · Sep 23, 2017 at 06:09 PM 0
Share

If Positive7's suggestions didn't help, we will need more details. Let's see the script in question.

avatar image Positive7 · Sep 25, 2017 at 04:41 AM 0
Share

We need more info can you post your UIController script please.

3 Replies

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by TypeFinalMagic · Sep 25, 2017 at 06:14 AM

After looking at the solution explorer in Visual Studio, I realized that my GameController script was not listed in the Asset folder in the explorer along with the other scripts. Then after more digging in Unity, I realized that the GameController script was misplaced in the scripts folder in the Standard Assets folder instead of the Scripts folder in the Asset folder containing all the folders and files. After moving the GameController script into the proper Scripts folder with all my other scripts, I was able to use the UIController script.

TLDR: Make sure that the script is placed in the same folder as the other scripts you are trying to use it with.

Comment
Add comment · 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
0

Answer by Raimi · Sep 23, 2017 at 04:16 PM

 private UIController uiController;
 
 void Start()
 {
      uiController = FindObjectOfType( UIController ); 
      // Should only be 1 UIController script in scene
 }

Not sure this is what you need, but hope it helps.

Comment
Add comment · Show 1 · 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 TypeFinalMagic · Sep 24, 2017 at 05:45 PM 0
Share

The problem is that I can't even put in the private UIController uiController; line without visual studio throwing the "type or namespace "UIController" cannot be found..." error

avatar image
0

Answer by Thaun_ · Sep 24, 2017 at 05:48 PM

Restarting Visual Studio makes it work for me, try that.

Comment
Add comment · Show 2 · 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 TypeFinalMagic · Sep 25, 2017 at 04:35 AM 0
Share

Restarting visual studio didn't help and neither did restarting the computer.

avatar image Thaun_ · Sep 25, 2017 at 05:32 AM 0
Share

Have you created a C# script via Visual Studio or Unity? If from Visual Studio, delete it and recreate it in Unity.

Have you tried update your .NET? or update Unity Tools?

Can you check if your file is in the Unity Project Explorer?

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

123 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

Related Questions

Draw call minimizer 1 Answer

Help with script 1 Answer

[C#] Quaternion Rotations with Input.GetAxis problems. 1 Answer

Respawn Point dont work, is because is a prefab? 2 Answers

[Help!]Unity FPS Health script error. 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