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
1 Answer
1
system
April 12, 2011, 2:24am
2
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!
Thanks, but still, is there any way to work around the code I'm working with?
– superventure