Seeking Help to access string variables in another script

Hi

I am new to unity and building my second unity App with some basic tutorials i followed. I am stuck in a issue where i am accessing a string in which a url is stored. I need to use the same value in another script but it gives me a NullReferenceException: Object reference not set to an instance of an object

I have searched for the error in the forum and was able to find couple of them,but none worked for me. Way i am accessing the string is as follows:

Script 1:

using UnityEngine;

using System.Collections;

publicclass ScriptA : MonoBehaviour {

public string bundleurl;

// Use this for initialization

void Start () {

bundleurl = “www.google.com”;

}

// Update is called once per frame

void Update () {

}

}

Script 2:

using UnityEngine;

using System.Collections;

publicclass ScriptB : MonoBehaviour {

public ScriptA scriptAB;

publicstring x;

// Use this for initialization

void Start () {

x = scriptAB.bundleurl;

Debug.Log(x);

}

// Update is called once per frame

void Update () {

}

}

Thanks in Advance.

ok, use [code ] [/code ] tags when pasting in code chunk into the forums, helps format and make them more readable…

how are you setting scriptAB to be populated with something? are you populating it in the inspector? if not, all you are doing so far is saying “there will be a variable called scriptAB” and haven’t actually set it to something that exists. When the code then tries to access the instance of that variable it doesn’t have one => null exception.