- Home /
Why am I not able to drag a script into another script's Game Manager anymore?
I have been following along with a YouTuber's tutorials (Brackeys) and have come upon a snag. I am not able to drag and drop my script (GameManager) into the Game Manager of one of my other scripts (End Trigger). This is for my Level 2 scene, I was able to do this before with my Level 1 scene.
I am sorry if this is not detailed enough, I just started two days ago and know little coding.
You are trying to drag a reference to a Game$$anonymous$$anager script from one GameObject in your hierarchy to a script on another GameObject in your hierarchy that has a field of type Game$$anonymous$$anager, correct? You aren't trying to drag it from the Assets folder, right? Are there any errors in any of your scripts? Unity might not let you drag and drop the reference if it detects any errors. So, check the console.
To get the best answers here, it is best to provide a code sample of your scripts so we can get a better idea of what could be causing the problem. Screenshots of your GameObject's inspector also help, especially in this case. You can format code using the "101010" button and attach pictures using the photo icon (or leave a link to imgur).
Answer by LeeroyLin · Jun 21, 2018 at 01:40 PM
I'm not sure what happened, but you can make sure your GameManager class name is equal to your c# file name. And make sure your GameManager class Inherits from MonoBehaviour. If you still have that problem, you should show me your script.
Game$$anonymous$$anager script is: using UnityEngine; using UnityEngine.Scene$$anonymous$$anagement;
public class Game$$anonymous$$anager : $$anonymous$$onoBehaviour {
bool gameHasEnded = false;
public float restartDelay = 1f;
public GameObject completeLevelUI;
public void CompleteLeve1 ()
{
completeLevelUI.SetActive(true);
}
public void EndGame ()
{
if (gameHasEnded == false)
{
gameHasEnded = true;
Debug.Log("GA$$anonymous$$E OVER");
Invoke("Restart", restartDelay);
}
}
void Restart ()
{
Scene$$anonymous$$anager.LoadScene(Scene$$anonymous$$anager.GetActiveScene().name);
}
}
End Trigger script is: using UnityEngine;
public class EndTrigger : $$anonymous$$onoBehaviour {
public Game$$anonymous$$anager game$$anonymous$$anager;
void OnTriggerEnter()
{
game$$anonymous$$anager.CompleteLeve1();
}
}
This is happening to everything. I cannot drag and drop anything into another script via the Inspector window.
Ok, I know what you mean and the problem is Game$$anonymous$$anager is a class, and you can only drag a GameObject to your EndTrigger script via the Inspector window. So, you have to drag your Game$$anonymous$$anager script to a GameObject first, even the object your EndTrigger attached. And then drag the GameObject to your EndTrigger's game$$anonymous$$anager property.
You are right, I had them as objects already and was but was using the scripts ins$$anonymous$$d. Thank you so much.
Your answer
![](https://koobas.hobune.stream/wayback/20220612165212im_/https://answers.unity.com/themes/thub/images/avi.jpg)