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 Bono · Oct 18, 2010 at 11:37 PM · instantiateplayerrandomstartplaces

Player starts instantiate at random places?

Hi!!! I want my player start on different locations everytime I start a new game? How do I do that? Just now my player is in the game at the same startplace! Thanks for help!!!!

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
1

Answer by zannghast · Oct 19, 2010 at 02:35 AM

One simple solution is to:

1) create several empty GameObjects, tag or name them as "spawnpoint" or something.

2) cache the transform of these GOs at the start of your game (via list, array, hashtable, etc)

3) randomly search through your array of spawnpoint transforms and use the resulting transform.position as your player's transform.position.

All that within your Awake().

Simple Hint: You could create a SpawnPoint manager script for your player, attach that to a SpawnPointManager GameObject, and do all those simple steps there instead. That way, you'd be separating the spawning logic of your character from any other stuff you'd be doing.

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 Bravini · Oct 19, 2010 at 02:28 AM

create a script with the code below and attach it to an object on the scene then delete your Player object. drag your Playerpreab on the inspector to the var PlayerPrefab.

var xpos : int;

var ypos : int;

var zpos : int;

var PlayerPrefab : Transform;

function Start () {

//set this to the area you want the player to appear according to the size of your map xpos = Random.Range(1,100); ypos = Random.Range(1,100); zpos = Random.Range(1,100);

Instantiate(PlayerPrefab, transform.position(xpos,ypos,zpos), (transform.rotation(0,0,0));

}

sorry for the bad indentation, still new to this.

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 Bono · Oct 19, 2010 at 08:01 AM

I tried Bravinis idea but it does not work, somting is wrong with the code! It says at the second last line 14 - expcting ), found ;.

Thankyou for awnser! Hope you will get back! or sombody know whats wrong? Thankyou!!!!!

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 zannghast · Oct 20, 2010 at 09:03 AM 0
Share

add a closing parenthesis to the last line like so:

Instantiate( PlayerPrefab, transform.position(xpos,ypos,zpos), (transform.rotation(0,0,0)) );

By the way, commenting on the 'answer' is the proper way to reply hehe. rules are rules xD

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

Random Player Respawn Points 3 Answers

How to access property of a prefab before Instantiating. 1 Answer

Make sure objects are not instantiated on each other 2 Answers

Triggering random sound on player 1 Answer

C# Spawn Random Object, at Random 2D Location 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