[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
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
}
}
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");
}
}
}
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.
Do not forget to accept the correct answers
I would, but nothing really helped me with my problems. :/