- Home /
Spawning objects
Hi everyone i made a script that spawning clones of some object but that is not spawning there where is my mouse can u help? respawn - a field where we should click to spawn a object dolar - object
public GameObject respawn;
public GameObject dolar;
private Transform trans;
private void Start()
{
trans = respawn.GetComponentInChildren<Transform>();
}
private void Update()
{
if (Input.GetMouseButtonDown(0))
{
dolar = Instantiate(dolar, new Vector3 (0,0,0), trans.rotation);
dolar.transform.parent = GameObject.Find("GameObject").transform;
}
}
Answer by tormentoarmagedoom · Jun 21, 2018 at 03:32 PM
You are very close!
You first instantiate it at the center of the Scene, at VEctor3.zero.
Then you make it child of another object.
If what you want is that the object apears at the parents position, You only need now to move it to the center of its parent (or the relative position you want)
dolar.transform.Localposition = Vector3.zero;
PD: You have an object in the scene called GameObject? Thats very baad practice maaan! change its name! GameObject is the basic variable name for objects, and you will get in trouble if use that word as a name....
Bye.
Bye!! :D
Thanks u had right! But is a small problem.. i want to make the object spawn in place where a click now object is spawnig on the middle of screen With the name u have too right really thanks for the help :D
Your answer
Follow this Question
Related Questions
Spawn Object in the sides of the screen 1 Answer
Spawn help? 0 Answers
script dosnt creat object where i want it to 1 Answer
Spawning Objects at location 3 Answers
Object reference not set to an instance of an object?! 1 Answer