- Home /
Instantiating an empty with a script attached
I have made an empty with a script attached into a prefab named Gameover. I then made a variable so that I could connect it to a script in the inspector. But when I try to instantiate it it throws this error:
Assets/Mouth.js(21,21): BCE0023: No appropriate version of 'UnityEngine.Object.Instantiate' for the argument list '(System.Type, UnityEngine.Vector3, UnityEngine.Quaternion)' was found.
This is the script trying to instantiate it:
var Gamover :GameObject; var pickedup :GameObject;
function Update () { }
function OnTriggerEnter(other:Collider){ if (other.name=="Bodypart"){
var bodyparts=(GameObject.FindGameObjectsWithTag("Bodypart")); for (var bodyparttodestroy : GameObject in bodyparts){ Destroy(bodyparttodestroy); } var turnpoints=(GameObject.FindGameObjectsWithTag("TP")); for (var turnpointtodestroy : GameObject in turnpoints){ Destroy(turnpointtodestroy); } Instantiate (Gameover); // Game Over or Lives deducted
} if (other.name=="Pickup"){ }
Debug.Log(other.name); Instantiate(pickedup,other.transform.position,other.transform.rotation); Destroy(other.gameObject); if (other.name!="Terrain"){ }
}
Answer by _Petroz · Feb 07, 2011 at 05:11 AM
This:
var Gamover :GameObject;
does not match this:
Instantiate (Gameover);
If it is going to be an empty game object with one script you could just do something like:
var g = new GameObject();
g.AddComponent("GameOverScript");
Your answer
![](https://koobas.hobune.stream/wayback/20220613102820im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Instantiating prefab at child (spawnlocations are arrays) 2 Answers
Checking if object intersects? 1 Answer
need help with instantiate'ing a Rigidbody 1 Answer
Instantiate Problem 1 Answer
Error in Spawning code 1 Answer