Call Functions from another scripts

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 :smile: 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.

If the function is static, you can call it by scriptName.functionName();

If the void is public, you can use getComponent, or SendMessage.

depents on what ScripB does and from what it inherits. if its a MonoBehavier, it´needs to be on a GameObject. Than you can do

ScriptB script = GetComponent<ScriptB>();
script.anyfunction();

if it doesnt inheret from MonoBehavier you can create a new instance

ScriptB script = new ScriptB();
script.anyfunction();

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();

But still they aren’t working ;'(

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, :smile:

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 () {
	
	}
}

and it works fine :smile: :smile: :smile: :smile: :smile: :smile: :smile: :smile:

Happy!! And thanks for giving me a clue guys :smile:

In js is it very simple.

if you use

Testfile1.js (the filename)

static var test = 1;

u can use the var in any other script in js

Testfile.test is the var u can use in any other js script

but scripting with .js is a little hard for me as i am scripting the whole gamein c#

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.