- Home /
How to move Instantiated 2D objects by 0.5 using arrows
I have this block breaker type of game. Where you start the ball and then it goes bouncing around, and you have to hit it back with a paddle. Now I want to have God Mode, where user can design a level him/herself. Each block is 1x1 size and there are 4 types of blocks as you can see. I have managed to code instantiating each with different keys(1,2,3,4), but now I have trouble designing them around. They all instantiate in the middle of the screen (0,0), on top of each other, and if the user might instantiate like 200 of them, I worry, the game might lag or something. Because the screen is 16x12. Here's my code for instantiating these prefabs, what can I do to improve and move them around, save and add next prefab and finally finish it. If they could test, it would be even better.
 public GameObject block3hit;
     public GameObject block2hit;
     public GameObject block1hit;
     public GameObject unbreakableBlock;
 
     void Start()
     {
         
     }
 
     private void Update()
     {
         
         SpawnBlock3();
         SpawnBlock2();
         SpawnBlock1();
         SpawnBlock4();
     }
 
     void SpawnBlock3()
     {
         if (Input.GetKeyDown(KeyCode.Alpha3))
         {
             GameObject k = Instantiate(block3hit);
             k.transform.position = new Vector2(0, 0);
         }
     }
 
     void SpawnBlock2()
     {
         if (Input.GetKeyDown(KeyCode.Alpha2))
         {
             GameObject k = Instantiate(block2hit);
             k.transform.position = new Vector2(0, 0);
         }
     }
     void SpawnBlock1()
     {
         if (Input.GetKeyDown(KeyCode.Alpha1))
         {
             GameObject k = Instantiate(block1hit);
             k.transform.position = new Vector2(0, 0);
         }
     }
     void SpawnBlock4()
     {
         if (Input.GetKeyDown(KeyCode.Alpha4))
         {
             GameObject k = Instantiate(unbreakableBlock);
             k.transform.position = new Vector2(0, 0);
         }
     }
 
Answer by tormentoarmagedoom · Apr 10, 2020 at 01:11 PM
I dont get your post.
Are you asking hot to move objects? change its transform.position.
https://answers.unity.com/questions/1716861/how-to-access-a-reference-variable-that-is-instant.html
Do something like:
 GameObject NewObject = Instantiate (blablabla)
Then change its transform.position
 NewObject.transform.position += New Vector2 (0,5f, 0);
Your answer
 
 
             Follow this Question
Related Questions
How to move Instantiated 2D objects by 0.5 using arrows(or mouse) 1 Answer
Why is my Prefab Instantiating when the Scene is Loaded? 2 Answers
Instantied 2D Prefab Is Invisible 1 Answer
The prefab you want to instantiate is null. 2 Answers
How do I make a clone of a prefab appear on the correct layer? [5.2.2f1] 1 Answer
 koobas.hobune.stream
koobas.hobune.stream 
                       
               
 
			 
                