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 Mr_Stump · Jan 23, 2012 at 09:06 PM · instantiatenetworkspawningplayers

Network Instantiate Pickup Problem

In my scene i've got an object, I spawn it using Network.Instantiate, at defined spanwpoints. I can get it to spawn just fine, but when there is more than 1 player, the object gets instantiated for every player. So if i have 2 players playing there will be 2 of these pickups in the exact same place.

What i have being done is that when a player collides with these pickups it increases their points. However, since there is multiple objects in the same place it duplicates their points again.

Is there a way to work around this? I seem to have hit a dead end. Here is a chunk of the code doing this:

 var dataPrefab : GameObject;
 var dataSpawned : boolean = true;
 var dataSpawnpoints : GameObject[];
 var dataSpawnPoint : GameObject;
 var lastSpawnPoint : GameObject;
  if (dataSpawned == false)
         {    
            dataSpawnpoints = GameObject.FindGameObjectsWithTag ("dataSpawnpoint");
            dataSpawnPoint = dataSpawnpoints[Random.Range(r, dataSpawnpoints.length)];
            if (lastSpawnPoint != dataSpawnPoint)
            {            
               lastSpawnPoint = dataSpawnPoint;
               dataSpawned = true;
               var newData = Instantiate(dataPrefab, dataSpawnPoint.transform.position, dataSpawnPoint.transform.rotation);    
            }
            else dataSpawnPoint  = dataSpawnpoints[Random.Range(r,dataSpawnpoints.length)];
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 ByteSheep · Jan 23, 2012 at 10:27 PM

Try adding the above script to an empty object in the scene. The reason I'd try that is because this game object, unlike your player object, will never have to be duplicated and so there will never be two instances of the same script.

P.s: If you need to pass a variable such as a boolean between two scripts then you can just set the variable as static like so:

static var NewVar : boolean;

and retrieve its value by using the scripts name (the name of the script where the variable is declared etc) and then adding the variable name to the end like so:

if...
OtherScriptName.NewVar == true
then...

This can be useful if you later need to check the variables that are now in the empty object, hope this helps :)

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 Mr_Stump · Jan 23, 2012 at 10:52 PM 0
Share

I appreciate your answer, however my scene is already set up as you mentioned : Currently, i have an empty game object in the scene named "gameSetup", the above code is already attached to that game object. The above script works for the most part, but it seems each player that is connected also instantiates the "dataPrefab" in the network, causing a build up in the same place.

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Players Not Showing 0 Answers

Networking | Getting buffered other - previous spawned players 1 Answer

Player 2 not spawning 1 Answer

Combination of Instance and random in a network game 2 Answers

UNet, how to create Internet game (like via PhotonNetwork) 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