Help (649590)

does any one know why i cant drag the script into the…

You have to give more informations.

What are you trying to do exactly?

Put AnotherScript in New Behavior Script public variable?

  1. Please use a better title than “help” for your post. This conveys little and will most likely be overlooked.
  2. If you mean you are putting something into the anotherscript slot, you need something in your scene with another script on it and you’ll drag that into the slot.
  3. I also hope you’re just learning and not really using those as names for your scripts.
1 Like

hi ,thanks for replying… im trying access the other script so that i can access its varriables but the console seems to keep saying object reference not set to an instance of an object , and heres my code

public class NewBehaviourScript : MonoBehaviour {

//this script is on “cube” not on “cube1”

public GameObject cube1;
public Script scriptToAccess;

public bool isCool;
public int myAge;

// Use this for initialization
void Start () {

scriptToAccess = GetComponent();
isCool = scriptToAccess.isCool;
Debug.Log(isCool);
myAge = scriptToAccess.myAge;
Debug.Log(myAge);

Are you trying to learn scripting in unity?

So, your GetComponent call will search the same gameobject and try to find a copy of “Script” attached to it, but when it doesn’t find it, it returns null, which is why you get a null reference error.

Because you declare scriptToAccess as public, you simply drag and drop in the inspector, making your getcomponent call unneeded unless both scripts are on the same object and you are intending to access that script on that object.

1 Like

thanks man thats why i was getting an error.
and yh im trying learn coding in unity its really difficult.