• 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 /
avatar image
0
Question by FuryFight3r · Mar 15, 2017 at 11:10 PM · gameobjectpositioninstantiate prefablocation

Instantiating Multiple Game Objects to the Position of a Current GameObject

Hey guys, Take this how you will, but I'm making a game that concludes of Marijuana Growth, i have everything working to a standard, from adding the soil to planting the seed, and even the tree growth, and the ability to harvest it once grown, but what i want, is when i harvest the plant, it spawns new objects (More seeds to plant (X2 to be exact so the growth doubles)) and a Block of Marijuana that is Sell-able, i have both the Prefabs for the Seeds and the Block, i have somewhat of an idea how to Instantiate Objects, i also have a current object in the game called HarvestSpawn (which is just a box collider that i hope to use as the spawn position for the items harvested, but they spawn at the very corner of the map in the edge of the game canvas.. Eg. 0 x 0 x 0 on the worlds map, Whereas my HarvestSpawn Object location is 114 x 80 x 373 which is where i would like my Harvested Objects to spawn, i also have a Parent that i would like these Instantiated objects to go, under the 'iObjects' GameObject in the main hierarchy, this is what i use for all my 'Intractable Objects'.... i have provided a short video, to better help for a solution to this issue I'm having, as i see a lot of people asking these questions and never getting the questions answered...

Any help will be greatly appreciated, the main thing I'm trying to achieve here is, with my harvest script, is there a way to use a current gameobject as a guide for the location for the Instantiating Objects?

Youtube Video Here

So when i harvest the plant, I'd wish for the 2 seeds and a block, spawn right where the plant was before harvested. Yes..... i did attempt to research this, yet none of the provided information that works for me, or the Instantiated objects do not spawn where they need to be spawned

instanciate-object.png (106.6 kB)
Comment
Add comment
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

2 Replies

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by Cherno · Mar 15, 2017 at 11:21 PM

 public int seedAmount = 2;
 public GameObject seedPrefab;
 public GameObject marBlockPrefab;
 public Transform harvestBlock_tr;
 public Transform parentObject_tr;
 
 public void Harvest() {
    for(int i = 0; i < seedAmount; i++) {
      GameObject seed_go = Instantiate(seedPrefab, harvestBlock_tr.position, Quaternion.identity) as GameObject;
         seed_go.transform.SetParent(parentObject_tr);
 }
  GameObject marBlock_go = Instantiate(marBlockPrefab, harvestBlock_tr.position, Quaternion.identity) as GameObject;
         marBlock_go.transform.SetParent(parentObject_tr);
 

 }
 
 
Comment
Add comment · 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
1

Answer by ifdef_ben · Mar 15, 2017 at 11:19 PM

You can specify the location of the instantiated object in the Instanciate() function. Like this,

 Instanciate(_yourSeedPrefab, new Vector3(114, 80, 373), Quaternion.identity);
Comment
Add comment · 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

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

86 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 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 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 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 avatar image avatar image

Related Questions

Is gameObject present at coordinates (x,y,z)? 1 Answer

How to Position a GUI at the Top-Right of the Screen? 2 Answers

C# Trouble getting object's current position on mouse down. 0 Answers

[CODE]Keep Gameobject position exactly at mouse cursor when cast float position to int 1 Answer

I tried to make a box to select units like you do in windows 1 Answer

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges