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 superventure · Apr 11, 2011 at 09:29 PM · loadlevelnullfind

Enter new level positions - check for players that might not be there

Hello unites! I travel with a party in my rpg- at times they may not be there (I recall some/ they may leave). Some of them have the same tags. How do I set it up to check if they are / are not null when I load a new level?

I have tried this in the start function for a spawn point

Pet = GameObject.FindWithTag("Pet").transform; Pet2=GameObject.FindWithTag("Pet2").transform; //etc finds...

Player = GameObject.FindWithTag("Player").transform; cam = GameObject.FindWithTag("MainCamera").transform;

Player.position = transform.position; Player.rotation.y = transform.rotation.y; cam.rotation.y = transform.rotation.y;

if(Pet!=null){ Pet.position =transform.position+transform.right*4; Pet.rotation.y = transform.rotation.y;

}if(Pet2 != null){ Pet2.position = transform.position+transform.right*-4; Pet2.rotation.y = transform.rotation.y; } }

thanks for any 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

1 Reply

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

Answer by Justin Warner · Apr 12, 2011 at 02:24 AM

http://unity3d.com/support/documentation/ScriptReference/PlayerPrefs.html

Use player prefs.

Save what the player has... Has a int 0 = not there, 1 = there.

Then you'd have, example.

//Start game, no allies;

PlayerPrefs.SetInt("dog", 0); PlayerPrefs.SetInt("friend", 0); PlayerPrefs.SetInt("cat", 0);

//Next level, dog joins;

PlayerPrefs.SetInt("dog", 1); PlayerPrefs.SetInt("friend", 0); PlayerPrefs.SetInt("cat", 0);

//Next level, dog leaves, both cat and friend comes in.

PlayerPrefs.SetInt("dog", 0); PlayerPrefs.SetInt("friend", 1); PlayerPrefs.SetInt("cat", 1);

//Etc.

Then at beginning of map, just use:

int dog = PlayerPrefs.GetInt("dog"); int friend = PlayerPrefs.GetInt("friend"); int cat = PlayerPrefs.GetInt("cat");

function Awake() { if(dog = 1){ //Spawn dog. }
if(friend = 1){ //Spawn friend. }
if(cat = 1){ //Spawn cat. } }

That should work =). Good luck!

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 superventure · Apr 14, 2011 at 07:26 PM 0
Share

Thanks, but still, is there any way to work around the code I'm working with?

avatar image Justin Warner · Apr 14, 2011 at 10:05 PM 0
Share

The code you have now isn't for bringing the characters on to the next "world". It's for spawning the characters... So you'd use that code in the spot where I put comments. //Spawn [object]... So yeah, you'd use that code =).

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

open door to next level, after 10000 points were added to your score (solved) 2 Answers

When player collides with object load next level 1 Answer

Best practice handling deleted object refences during SceneManager.LoadScene 0 Answers

Anyway to save which seen the player was on, then load that scene back from another one at a different time? 2 Answers

Application.LoadLevel not working 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