hey guys, just a simple one… ive attached this script to a tree, and i want it so that when clicked, the tree is destroyed and instantiated in its place is a prefab of some logs.
this is my script:
var prefab : GameObject;
var tree = Transform;
function OnMouseDown () {
Instantiate (prefab, tree);
Destroy(gameObject);
}
but it says that “No appropriate version of ‘UnityEngine.Object.Instantiate’ for the argument list ‘(UnityEngine.GameObject, System.Type, int)’ was found.” can you guys help?
public class makeLogs : MonoBehaviour {
// Use this for initialization
public GameObject logs;
void Start () {
}
// Update is called once per frame
void Update () {
if(Input.GetKeyDown(KeyCode.A))
{
Instantiate(logs,transform.position,Quaternion.identity);
Destroy(gameObject);
}
}
}
this is c# but you should get the idea, the keypress is just to simulate your condition for activating the instantiation and destruction
the error you are getting is because you have not correctly filled out the parameters of the instantiate command. the unity script reference site will help you with this
edit : this is assuming that the script is attached to the tree.
I know this is an old as thread too but someone might have a similar question in the future so! Here is my crack at it.
var Tree : GameObject;
var Logs : GameObject;
var LogSpawn : Transform; //This is an empty you attach to the tree//
function Update(){
if(Input.GetMouseButtonDown(0)){
Destroy(Tree);
SpawnLogs();
}
}
function SpawnLogs(){
Instantiate(Logs, LogSpawn.transform.position, LogSpawn.transform.rotation);
}
//You might need it to Be Logs.transform! You might also need it to say Destroy(Tree.transform) i cannot remember I use an object pool its a bit different with that//