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 /
avatar image
0
Question by simpleone · Apr 18, 2011 at 08:11 PM · prefabspawnspawnpoint

Prefab to spawn on right spot

I wanted my prefab to spawn over and over again and used this --> http://unity3d.com/support/documentation/ScriptReference/MonoBehaviour.InvokeRepeating.html

It's works almost perfect - The Prefab spawns over and over again but now on the right spot...

I created a new "GameObject" and added the script but the prefab spawns all over the map - Anyone know how I can fix this?

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

1 Reply

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

Answer by Kourosh · Apr 18, 2011 at 08:33 PM

You need to define a spawn point and pass the position of it to the Instantiate function. To do so simply create an empty gameobject and rename it as "SpawnPoint" and then place it where you want your prefabs be instantiated from. Then in your script do this:

var spawnPoint:Transform; //assign "SpawnPoint".

function LaunchProjectile () { var instance : Rigidbody = Instantiate(projectile, spawnPoint.position, Quaternion.identity);

//To Shoot in random directions: instance.velocity = Random.insideUnitSphere * 5; //This is causing it to shoot all over the place. cause it's spawning in random directions. whereas if you want a defined direction you would use next line instead.

//To have a predefined direction use this line: instance.velocity = spawnPoint.forward * 5; //make sure the forward axis of the spawn point gameobject is looking at your desired direction.

}

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 simpleone · Apr 18, 2011 at 09:00 PM 0
Share

Thx for the post, I created a new gameobject and renamed it but I just get a $$anonymous$$ identifier: 'Projectile'. .....

avatar image Kourosh · Apr 19, 2011 at 12:06 AM 1
Share

Ye, cause you need to declare the projectile variable which I didn't bother doing. It's already in the link you used in your question.

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.

Follow this Question

Answers Answers and Comments

No one has followed this question yet.

Related Questions

spawn prefabs as children of another game object 2 Answers

spawning rigidbodies next to each other 0 Answers

Spawn a prefab 1 Answer

Randomly spawn the same object with different properties consistently. 2 Answers

Random spawnpoint where only one prefab can spawn! 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