- Home /
I need to move a clone of a prefab to a specific position after it instantiates
using System.Collections; using System.Collections.Generic; using UnityEngine;
public class SpannerPickUp : MonoBehaviour {
public int Value;
public GameObject pickUpEffect;
private void OnTriggerEnter(Collider other)
{
if (other.tag == "Player")
{
FindObjectOfType<GameManager>().AddSpanner(Value);
//this new instance needs to move to a specific position
Instantiate(pickUpEffect, transform.position, transform.rotation);
Destroy(gameObject);
}
}
}
Answer by Darkforge317 · Feb 12, 2018 at 03:34 PM
Create a GameObject variable and make it equal to your instantiation.
GameObject spawnedObject = Instantiate(pickUpEffect, transform.position, transform.rotation);
And then change the position of spawnedObject.
Alternatively, ins$$anonymous$$d of using transform.position
as an argument to Instantiate, you can just use the position you want the object to spawn at
Your answer
Follow this Question
Related Questions
instantiated GameObject Prefab jumps in air after instantiate 1 Answer
How can I naming each instantiated object in "for" loop ? 1 Answer
Translate a 2D position to a 3D space 1 Answer
hello there I am Trying to Instantiate a 1 of 5 GameObjects 0 Answers
Change animation at runtime with Mecanim 0 Answers