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 importguru88 · May 10, 2016 at 06:00 AM · scripting problemerrorscript error

How do I access scripts

Hello I trying to access two scripts . Im try to access the MyClock Script and the ScoreManager Script from the PlayerPreference Script. I've have type in the codes I need in the PlayerPreference script , so I can access ScoreManager . I gotten an error error CS0246: The type or namespace name `scoreManager' could not be found. Are you missing a using directive or an assembly reference? I thought I had code it right . Here is the scripts :

using UnityEngine.SceneManagement; using UnityEngine.UI; using UnityEngine;

public class PlayerPreference : MonoBehaviour { private scoreManager scoreManagerScript; private MyClock MyClockScript;

  void Awake () 
  {
      scoreManager = GetComponent<ScoreManagerScript>();
      myClock = GetComponent<MyClockScript>();
  }
  
  void Update(){
      
      if ((myClock != NULL) && (scoreManager != NULL)  &&
  (myClock.m_leftTime >= scoreManager.score))
  {
       SceneManager.LoadScene("time");
      
  }
      
  }     
  
  }
  
  





using UnityEngine; using System.Collections; using UnityEngine.UI;

public class ScoreManager : MonoBehaviour { public static int score; private Text text;

  void Awake () 
  {    
      text = GetComponent <Text> ();
      score = 0;


  
  }
 
  void Update ()
 {
          text.text = "Score :" + score;
      }
  
  

}

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

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Highwalker · May 10, 2016 at 06:13 AM

You're trying to access the scripts within the same object. You would have to use FindGameObjectWithTag. Or, you can simply set some public variables and then set them in the editor. So simply change the variables from private to public. And then you'll be able to select the right object in the editor's inspector window.

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 tanoshimi · May 10, 2016 at 06:24 AM

 private scoreManager scoreManagerScript;

should be:

 private scoreManagerScript scoreManager;
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 Highwalker · May 10, 2016 at 06:35 AM 0
Share

that too ^^. Same with the $$anonymous$$yClock variable. Didn't even notice that error.

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Can anyone provide some help with that error ? 1 Answer

Can't add script to anything error 1 Answer

Help with script 1 Answer

Hey guys, im starting do make a RPG game and in the Level system script(I called it "PlayerStatsController") i have an error: Parser Error : Unexpected symbol `public'. My script above: 1 Answer

Script wont work for me please give me answers or a new script,camera folllow script is very janky and twitchs alot please help 2 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