title: how to instantiate a prefab in unity3d at position (2D Game)
body: <p><a href="https://i.stack.imgur.com/5YeaY.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/5YeaY.png" alt="enter image description here" /></a><a href="https://i.stack.imgur.com/KHY3G.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/KHY3G.png" alt="enter image description here" /></a>I am trying to instantiate a prefab and I want it's location to be the exact same as the position of game object with name &quot;spawnedPos&quot; . Somehow the prefab is not instantiated on the exact same position.</p>
  <p>code :</p>
  <pre><code>using System.Collections;
  using System.Collections.Generic;
  using UnityEngine;
  
  public class ShurikenSpawn : MonoBehaviour
  {
      public GameObject[] gameReference;
      public GameObject spawnedShar;
      public Vector2 pos;
      public Transform playerPos;
      public float posX, posY;
      public Transform spawnedPos;
      
      void Start()
      {
  
       
  
      }
      private void Update()
      {
          spawnedPos = GameObject.FindWithTag(&quot;spawnedPos&quot;).transform;
          playerPos = GameObject.FindWithTag(&quot;Player&quot;).transform;
          //posX = playerPos.position.x;
          //posY = playerPos.position.y;
        //  pos = new Vector2(posX, posY);
          spawnedPos.position = playerPos.transform.position;
         
        
         // spawnedPos.transform.position = pos;
         
          if (Input.GetKeyDown(KeyCode.F))
          {
              spawnedShar = Instantiate(gameReference[0],spawnedPos);
             
           }
      }
      
  }
  </code></pre>
  <p><a href="https://i.stack.imgur.com/PzynN.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/PzynN.png" alt="enter image description here" /></a></p>