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 /
  • Help Room /
avatar image
1
Question by Jinougeration · Sep 30, 2016 at 06:36 PM · beginneraccessing scriptsc# to javascript

[Beginner] C# PauseMenu script can't access the scripts from my FirstPersonController (C# & JS)?

Hey Guys, as you can read in my question above I guess I have problems with the access between my scripts and I am a total beginner in Unity and scripting. So, to explain my problem to you guys :) ..my FirstPersonController has a Mouse Look script in C#, a Character Motor script in JS and a FPS Input Controller also in JS. I will just mention these at the moment, because I think that these are the important scripts that may cause the problem.

This is my script for the pause menu in my game. Everthing works well, except set the time to zero and the player+main camera can still move, while the pause menu runs. My console do not show any errors.

 using UnityEngine;
 using System.Collections;
 using UnityStandardAssets.Characters.FirstPerson;
 
 public class PauseGame : MonoBehaviour {
     public Transform canvas;
     public Transform pauseMenu;
     public Transform Player;
     SaveGame saveGame;
 
 
     // Update is called once per frame
     void Update () {
         if (Input.GetKeyDown (KeyCode.Escape))
         {
             Pause();
         }
     }
     public void Pause()
     {
         if (canvas.gameObject.activeInHierarchy == false)
         {
             if (pauseMenu.gameObject.activeInHierarchy == false)
             {
                 pauseMenu.gameObject.SetActive (true);
             }
             canvas.gameObject.SetActive (true);
             Time.timeScale = 0;
             Player.GetComponent<FirstPersonController> ().enabled = false;
             saveGame = gameObject.GetComponent<SaveGame> ();
             saveGame.SaveGameSettings (true);
 
         } else
         {
             canvas.gameObject.SetActive (false);
             Time.timeScale = 1;
             Player.GetComponent<FirstPersonController> ().enabled = true;
         }
     }
 }
 

I hope someone can help me out, somehow. It's maybe totally obvious, but I'm clueless on this. :/

By the way, I may not know all of the technical terms and my english is also not the best. :P

Comment
Add comment · Show 2
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 TBruce · Sep 30, 2016 at 06:41 PM 0
Share

Ins$$anonymous$$d of adding the FirstPerson namespace like this

 using UnityStandardAssets.Characters.FirstPerson;

try try it like this

 namespace UnityStandardAssets.Characters.FirstPerson
 {
     public class PauseGame : $$anonymous$$onoBehaviour
     {
         // yada yada yada
     }
 }
avatar image Jinougeration TBruce · Oct 01, 2016 at 09:24 AM 0
Share

Thanky for your help, but it's still not working :/ ..

I also tried it with an other C# script, because I thought that maybe this will work, but it's still the same and additionally my resume button also no longer works :P ..

 using UnityEngine;
 using System.Collections;
 using UnityEngine.Scene$$anonymous$$anagement;
 
 namespace UnityStandardAssets.Characters.FirstPerson {
     
 public class UI$$anonymous$$anager : $$anonymous$$onoBehaviour {
 
     GameObject[] pauseObjects;
 
     //Use this for initialisation
     void Start () {
         Time.timeScale = 1;
         pauseObjects = GameObject.FindGameObjectsWithTag("ShowOnPause");
         hidePaused();
     }
 
     //Update is called once per frame
     void Update () {
 
         //uses the escape button to pause and unpause the game
         if(Input.Get$$anonymous$$eyDown($$anonymous$$eyCode.Escape))
         {
             if(Time.timeScale == 1)
             {
                 Time.timeScale = 0;
                 showPaused();
             } else if (Time.timeScale == 0){
                 Debug.Log ("high");
                 Time.timeScale = 1;
                 hidePaused();
             }
         }
     }
 
 
     //Reloads the level
     public void Reload(){
         Scene$$anonymous$$anager.LoadScene("Insel_Survive");
     }
 
     //Controls the pausing of the scene
     public void pauseControl(){
         if(Time.timeScale == 1)
         {
             Time.timeScale = 0;
             showPaused();
         } else if (Time.timeScale == 0){
             Time.timeScale = 1;
             hidePaused();
         }
     }
 
     //Shows objects with ShowOnPause tag
     public void showPaused(){
         foreach(GameObject g in pauseObjects){
             g.SetActive(true);
         }
     }
 
     //Hides objects with ShowOnPause tag
     public void hidePaused(){
         foreach(GameObject g in pauseObjects){
             g.SetActive(false);
         }
     }
 
     //Loads inputted level
     public void LoadLevel(string level){
         Scene$$anonymous$$anager.LoadScene("Start$$anonymous$$enu");
     }
 }
 
 }

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by AurimasBlazulionis · Oct 01, 2016 at 10:21 AM

You can not access JS from C# and vice versa. You have 2 options.

First option, convert JS to C# or C# to JS.

And the other option is to move your C# script to Plugins or Standard Assets folder in the root of your project. If that does not work, move JS code to Plugins or Standard Assets folder.

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 Jinougeration · Oct 01, 2016 at 10:43 AM 0
Share

Ok, thanks!

avatar image AurimasBlazulionis Jinougeration · Oct 01, 2016 at 10:54 AM 0
Share

Do not forget to accept the correct answers

avatar image Jinougeration AurimasBlazulionis · Oct 04, 2016 at 11:21 AM 0
Share

I would, but nothing really helped me with my problems. :/

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

How to write a script for an existing button 1 Answer

I know c plus plus and oop ? now what should i learn to start unity ? java script or c# ? i would be pleased with your right guide !!! 1 Answer

How to go about making a card game like the 8 ball pool app from miniclips 0 Answers

How to instantiate UI elements centered around an empty object 1 Answer

Rotating a Model 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