• 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 darkal · Oct 21, 2013 at 01:48 PM ·

Make item spawn at a empty game object location.

i want the item to be be spawned at the location of a empty game object i have the variables all ready made if u need the whole script comment and ill post it

           function Update ()
           {
                          if (drop)
            {
                Instantiate (clone);
                Instantiate (clone1);
                drop = false;
                Destroy (pick);
            }
         }
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

3 Replies

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

Answer by ArkaneX · Oct 21, 2013 at 02:15 PM

You have to use Instantiate overload and provide position and location of the instantiated object. Assuming emptyObject is a GameObject, you can use:

 Instantiate(clone, emptyObject.transform.position, Quaternion.identity);


Comment
Add comment · Show 2 · 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 darkal · Oct 22, 2013 at 12:44 AM 0
Share

it works but im wondering if there is a way to make it the player it spawns on? i tried it works true but the prefabs i have set wont accept the player i have in the game granted it does 100% work im just wondering if there is a way to make it so were ever my character is the cube spawn there?

ps- if u dont know thats fine im just wondering if there is a way?

avatar image ArkaneX · Oct 22, 2013 at 07:21 AM 0
Share

If I understand you correctly, you now want to spawn your object at the location of the player. It should work just fine, if you put your Player position as the second argument, e.g. Player.transform.position (assu$$anonymous$$g Player is a GameObject).

avatar image
0

Answer by nastasache · Oct 21, 2013 at 02:15 PM

 // Create an empty object in scene
 // Attach this script to any object in scene
 // See: emptyObject.transform.position, emptyObject.transform.rotation
 // Location and rotation are params 2 & 3 of Instantiate()
 
 var emptyObject : Transform; // Drag empty object here
 
 var drop = false;
 
 var clone : Transform; // Drag your clone obj here
 
 function Start() {
     drop = true;
 }
 
 function Update ()
 {
     
     if (drop)
     {
         Instantiate (clone, emptyObject.transform.position, emptyObject.transform.rotation); 
         
         drop = false;
         
     }
 }
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
0

Answer by franman007 · Jul 11, 2017 at 03:21 AM

Alright but what if there's instances for spawn points how do I get the items to spawn at the locations these spawn points are located at?

 public float spawnTime;
     private GameObject respawnPrefab;
 
     // Use this for initialization
     void Start () {
         respawnPrefab = GameObject.Find("BallSpawnPoint");
         InvokeRepeating("BallSpawn", 0, spawnTime);
     }
     
     void BallSpawn () {
         var ball = Resources.Load("Ball");
         Instantiate(ball, respawnPrefab.GetComponent<Transform>().position, respawnPrefab.GetComponent <Transform>().rotation);
     }
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

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

18 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

Related Questions

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

How to import the object from server to unity 2 Answers

Can someone help me fix my Javascript for Flickering Light? 6 Answers

Material doesn't have a color property '_Color' 4 Answers

Setting Scroll View Width GUILayout 1 Answer


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