Change position of Instantiated object (2D Game)

Updated on July 19, 2018 in Unity
Share on Facebook0Tweet about this on TwitterShare on Google+0Share on Reddit0
1 on July 15, 2018

Hi everyone,

I have this code that handles the spawning of an instantiated particle system whenever my bullet object hits something (game is 2D)

Debug.Log("Bullet collided with background and was destroyed");
 Destroy(this.gameObject);
 GameObject clone = (GameObject)Instantiate(hitEffectYellow, transform.position, transform.rotation);
 Destroy(clone, 1f);

I’d like to be able to change the Y position of the instantiated object because at the moment it spawns at the start of the bullet trail instead of at the tip of the bullet. I have tried some ways to do it but after some research none of them even made sense to try in the first place, so i’m asking you guys here to help me figure out how to do this.
I think it’s something really simple but i’ve searched around and haven’t been able to find anything that worked yet. Just for clarification, i’d like the instantiated object to keep spawning at the position of the bullet object, but modifying the Y coordinate so it spawns further “up”.

Any help would be appreciated!

  • Liked by
Reply
0 on July 19, 2018
float yourYposition;
clone.transform.position = new Vector3(clone.transform.position.x, yourYposition, clone.transform.position.z);
  • Liked by
Reply
Cancel