Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
This question was closed May 05, 2014 at 02:23 PM by Hexer for the following reason:

I found the Problem and am now trying to solve it, by assigning the var Spawn(1,5) to the gameobject in the hierarchy instead of the asset folder

avatar image
0
Question by Hexer · May 05, 2014 at 12:47 PM · javascriptinstantiatetransform.position

Doesn't Instantiate at the assigned EmptyObject

I HAVE FOUND THE PROBLEM, I SHOULD NEVER HAD MADE THOSE PREFABS BECAUSE THEY DON"T UPDATE ON RUN, SO I ASSIGNED THE SPAWNS TO THE GAMEOBJECT IN THE HIERARCHY INSTEAD

Hello fellow ForumMembers,

I found a way to Instantiate my Obstacles to an empty gameobject. The next problem I encounter is that when I try to move the empty gameobject ,where it suppose to be spawned. It doesn't update its position. Also it seems like that the objects keep spawning at that same position even when I move the gameobjects to another position before pressing on start.

This is the script I made

 var Spawn1 : GameObject;
 var Spawn2 : GameObject;
 var Spawn3 : GameObject;
 var Spawn4 : GameObject;
 var Spawn5 : GameObject;
 //The Obstacle
 var Obstacles : GameObject;
 
 InvokeRepeating("Start2", 0, 1.0);
 
 function Start2()            
 {                 
 if(GameObject.Find("Player").GetComponent(Rigidbody2D).isKinematic == false){
 
  var Spawn = Random.Range(0,4);
 
   if(Spawn == 0){
   Debug.Log("spawn0");
 Instantiate(Obstacles, Spawn1.transform.position, Quaternion.identity);
  }
   if(Spawn == 1){ 
   Debug.Log("spawn1");
 Instantiate(Obstacles, Spawn2.transform.position, Quaternion.identity);
  }
   if(Spawn == 2){ 
   Debug.Log("spawn2");
 Instantiate(Obstacles, Spawn3.transform.position, Quaternion.identity);
  }
   if(Spawn == 3){ 
   Debug.Log("spawn3");
 Instantiate(Obstacles, Spawn4.transform.position, Quaternion.identity);
  }
   if(Spawn == 4){ 
   Debug.Log("spawn4"); 
 Instantiate(Obstacles, Spawn5.transform.position, Quaternion.identity);
  }
  }
  }

InvokeRepeating let me call the function each second.

var Spawn 1: GameObject; is an empty Object were the Obstacles should be Instantiate.

Random.Range let me to randomize the position of the Obstacle each time the function has been called.

here have a picture. alt text

thx for reading.

sowa.png (47.3 kB)
Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Hexer · May 05, 2014 at 01:50 PM 0
Share

I experiment with my project and it seems the problems are the prefabs, the position of prefabs doens't change in the Asset folder, but those are actually the standart position for the instaniate.

1 Reply

  • Sort: 
avatar image
0

Answer by JacobHockey13 · May 05, 2014 at 04:56 PM

 var Spawn1 = Vector3(0,0,0);
 var Spawn2 = Vector3(0, -1, 0;
 var Spawn3 = Vector3(0, -2, 0) ;
 var Spawn4 = Vector3(0, -2, 0);
 var Spawn5 = Vector3(0,-2, 0);
 //The Obstacle
 var Obstacles : GameObject;
  
 InvokeRepeating("Start2", 0, 1.0);
  
 function Start2()      
 {           
 if(GameObject.Find("Player").GetComponent(Rigidbody2D).isKinematic == false){
  
  var Spawn : int = Random.Range(0,4);
  
   if(Spawn == 0){
   Debug.Log("spawn0");
 Instantiate(Obstacles, Spawn1, Quaternion.identity);
  }
   if(Spawn == 1){ 
   Debug.Log("spawn1");
 Instantiate(Obstacles, Spawn2, Quaternion.identity);
  }
   if(Spawn == 2){ 
   Debug.Log("spawn2");
 Instantiate(Obstacles, Spawn3, Quaternion.identity);
  }
   if(Spawn == 3){ 
   Debug.Log("spawn3");
 Instantiate(Obstacles, Spawn4, Quaternion.identity);
  }
   if(Spawn == 4){ 
   Debug.Log("spawn4"); 
 Instantiate(Obstacles, Spawn5, Quaternion.identity);
  }
  }
  }

Just change the variables to the desired positions. I would also recommend you declare variables for your new instantiated objects.

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Hexer · May 05, 2014 at 07:22 PM 0
Share

Well, your script is some kind the same as $$anonymous$$e. The only difference is that I can set the spawn to an empty object I set in the scene. With this I can easily change the spawn positions while your script is bound to an exact position. Spawning them in the wished Y.X.Z position wasnt really the problem.

I had those spawn position added as a Child of the camera. So when the camera moves ,the spawnpoints will also move along. The problem was that it didnt update the location of the spawnpoint. Even when I manually re position the spawnpoints.

So ins$$anonymous$$d of having a var :gameobject;

I made a var spawn1 = GameObject.Find("spawn1"); and put it in the function start2() This worked out well.

Thanks anyway for your response. ~Hexer

Follow this Question

Answers Answers and Comments

21 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Why is transform.position of a prefab that's been instantiated different than a gameobject created on the scene, when they are in the exact same position? 1 Answer

Calculating where to position instantiated clone 1 Answer

Classes VS Variable Scripts 1 Answer

Shotgun Spread Issue 1 Answer

Null Reference Exception transform position y 2 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges