Just think that i have two scripts scriptA and scriptB.
ScriptB has a function called public void anyfunction
and how do i access it with scriptA
scriptB is not active in any of the gameobejcts in the scene Please help me,
i tried using the method where make a variable of the type of the script and then call the function in start…but shows me one error, Assets/Run Forever/Scripts/GameData/GameCompiler.js(4,22): BCE0018: The name ‘TilesGenerator’ does not denote a valid type (‘not found’).
Need for C# or .JS as i can translate between them.
when i use public static, i can’t see it. I have to use MonoBehavier option as I use Instiate option the scripts and it functions…I don’t have the script active in any GameObjects and I don’t want it to be active.
I tried using the following things,
public static void anyfunction(){}
static void anyfunction(){}
public void anyfunction(){}
void anyfunction(){}
nothing can come up with the thing i want. It doesn’t show up in the other script if i type
scriptA.anyfunction;
[and]
public scriptA name = new scriptA;
name.anyfunction();
ok i got it working,
my first script which has the function has this thing
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class scriptA : MonoBehaviour {
public void anyfunction(){
.
.
.
.
.
}
}
and rhe second script has this,
using UnityEngine;
using System.Collections;
public class GameCompiler : MonoBehaviour {
public scriptA namel;
// Use this for initialization
void Start () {
namel = new scriptA();
namel.anyfunction();
}
// Update is called once per frame
void Update () {
}
}
You should NEVER create an instance of scriptA on your own when it inherits MonoBehaviour. You have to either call GetComponent or AddComponent to use them in a valid way.
If you don’t want scriptA to be visible in the inspector, it should not inherit from MonoBehaviour. If it should be visible in the inspector, it has to inherit from MonoBehaviour and you have to use GetComponent/AddComponent to acess/create it.