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 Matt 5 · Mar 26, 2012 at 08:31 PM · loading

Loading Spawn points based on decision

Hi Everyone

I have this code I'm trying to alter to fit my game style but I'm having an issue.

What I want is once the player picks his or her team that will decide which Spawn area they will start in.So If they pick Red team they will Spawn where the red team should and the same idea with the blue team. Here is the code that handles the choice. I got this code from http://www.M2H.nl)

private var chooseTeamInt = 0; private var chooseTeamNames : String[] = ["Red", "Blue"]; private var ffInt = 0; private var ffNames : String[] = ["Off", "On"]; private var chosenPlayerInt = 0;

if (serverGameTypeSelected != "DM") { GUI.Label (Rect (110, 120, 150, 20), "Choose Team: "); chooseTeamInt = GUI.Toolbar ( Rect (250, 120, 100, 20), chooseTeamInt, chooseTeamNames);

     switch (chooseTeamInt)
     {
     case 0:
     PlayerPrefs.SetString("playerTeam", "RedTeam");
     break;
     case 1:
     PlayerPrefs.SetString("playerTeam", "BlueTeam");
     break;
     }

This is the code that handles the loading of the player when the game type is chosen.

void OnNetworkLoadedLevel() {

     GameObject[] spawnPoints = GameObject.FindGameObjectsWithTag("SpawnPoints");
     Debug.Log("Spawns: " + spawnPoints.Length);

     Transform spawnpoint = spawnPoints[UnityEngine.Random.Range(0, spawnPoints.Length)].transform;
     Transform newTrans = Network.Instantiate(playerPref, spawnpoint.position, spawnpoint.rotation, 0) as Transform;
     
 }
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
0

Answer by DaveA · Mar 26, 2012 at 08:33 PM

Why not have tags like "RedSpawnPoints" and "BlueSpawnPoints" and assign them accordingly?

Comment
Add comment · Show 4 · 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 Matt 5 · Mar 26, 2012 at 08:36 PM 0
Share

Its s network game so it would depend first on the choice I do have those tags set up my problem is that I'm still new to network games so the company I work for want it done this certain way so I can't do it another way. They want the spawn to be deter$$anonymous$$ed but what $$anonymous$$m the player picks and spawn in that area according the spawn areas set in the Editor

avatar image DaveA · Mar 26, 2012 at 08:58 PM 0
Share

Yeah so you can do that. When the player makes his choice, you send that to other players, and when that choice is received, it picks the matching set of spawnpoints by tag (using tags like "RedSpawnPoints" ins$$anonymous$$d of simply "SpawnPoints")

avatar image Matt 5 · Mar 29, 2012 at 07:23 PM 0
Share

Here is the updated code I did now I tried doing that and now I get this error Tag:RedSpawn undefined. I'll put it in the answers field

avatar image Matt 5 · Mar 29, 2012 at 08:48 PM 0
Share

I even tried doing this

void OnNetworkLoadedLevel() {

     if (boolean == false)
     {
         GameObject[] RedSpawnPoint = GameObject.FindGameObjectsWithTag("RedSpawnPoint");
         Transform spawnpoint = RedSpawnPoint[UnityEngine.Random.Range(0, RedSpawnPoint.Length)].transform;
         Transform newTrans = Network.Instantiate(playerPref, spawnpoint.position, spawnpoint.rotation, 0) as Transform;
     }
     
     
     else if(boolean == true)
     {
         
         GameObject[] BlueSpawnPoint = GameObject.FindGameObjectsWithTag("BlueSpawnPoint");
         Transform spawnpoint = BlueSpawnPoint[UnityEngine.Random.Range(1, BlueSpawnPoint.Length)].transform;
         Transform newTrans = Network.Instantiate(playerPref, spawnpoint.position, spawnpoint.rotation, 0) as Transform;
     }

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Spawning in a specified location 2 Answers

Loading font runtime from file 0 Answers

Change loading screen to images in Flash build 0 Answers

How can I load multiple files from a hosted folder? 1 Answer

My unity project won't load my level for editing on a different PC 0 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