- Home /
instatiating an object from another object and automatically tagging it to be collected
Hi all,
what i need is to make an object (3d model) like a machine in a factory instantiate another object (3dmodel) like a product and of course to collect it like the famous item collection game , it has to be tagged.
Does anyone know how to do that?
Perhaps a script will be helpful...................
Answer by amr nasr · Oct 22, 2010 at 09:39 PM
Okay here is what i found after some research for the timer to be added so that the machine will produce a chocolate every 10 seconds
var myTimer : float=10.0; var chocolate:Transform;
function update () {
if(myTimer>0){ myTimer-=Time.deltaTime;
}
if(myTimer<=0) {
var instatiated = Instantiate(chocolate, transform.Find("Machine").transform.position, Quaternion.identity);
insantiated.tag = chocolate;
////////////////////////////////////////////////////
////Shall i add here ------------myTimer=10.0; again
///////////////////////////////////////////////////
}
}
I would really appreciate if someone answers me
Answer by kyle · Oct 22, 2010 at 06:57 PM
I believe you need to do this: code//
var WhatEverYouWantHere : Transform;
function update () { //call what you want to happen to cause the instantiate if(whatever) { var instatiated = Instantiate(WhatEverYouWantHere, transform.Find("the thing you want it made at").transform.position, Quaternion.identity); insantiated.tag = collectable; } }
that should probably do it...I hope.
Thanks very much for the reply So shall i attach the script to an empty object and that one will find the first object that will instantiate the other object. another thing that i want is to make it do that every 10 second for example to do that
so according to my understanding because i am not a geek yet in unity game engine
the script will look like this
var chocolate:Transform;
function update() {
if(whatever){
var instantiated=instantiate(chocolate.transform.Find("$$anonymous$$achine").transform.position, Quaternion.identity);
insta
instantiated.tag=chocolate;}
}
Not object#1 prefab is which is the one instantiating the other object is called $$anonymous$$achine, object #2 is called chocolate--------------------
Is what i did correct.......................
and How to modify the code to do that every 10 seconds
i would really appreciate if you answer me regarding that
no it's not (chocolate.Transform.Find("$$anonymous$$achine").transform.position, Quaternion.identity);
it's (chocolate, transform.Find("$$anonymous$$achine").transform.position, Quaternion.identity);
Answer by kyle · Oct 23, 2010 at 01:46 PM
I'm pretty sure that you don't have to add the timer there again since you already called the function and everything good job doing some research on your own and not sitting around and waiting for the answer which some people do, do.
EDIT:
actually looking at your comment again yes you do or else it's going to keep subtracting and not stop, oh and also, ten seconds seems a little long to wait for an Instantiate.
K.N.
Your answer
Follow this Question
Related Questions
Spawn many object 1 Answer
Random array issue C# 2 Answers
Destroy and instantiate far objects 2 Answers
[Closed]Instantiate object to spesific location 1 Answer
How can i randomly create an array of objects without colliding one another? 1 Answer