I am making a pokemon like game where you can catch pokemon in the wild. I have everything down to where a boolean is true if I caught it. I want to then if that boolean is true to add the caught pokemon to a list in the player prefs. Basically I don't remember how to make list because I learned how to a long time ago and forgot and I don't know how to store a list in the player prefs. I was looking at the classes unity created in Javascript has and I couldn't find one called list. Is it called something else or is there none. I know c# has it why not javascript.
Here is my code for catching a pokemon.
#pragma strict
private var Enemyscript : Enemy;
private var Healthscript : Health;
var strength : int;
var health : int;
var Monster : GameObject;
var once : boolean;
var RandNum : int;
var catchable : boolean;
var caught : boolean;
function Start () {
caught = false;
RandNum = Random.Range(0,50);
}
function Update () {
if(catchable){
if(strength*health >= 480 && RandNum < 3){
caught = true;
}
if(strength*health >= 460 && strength*health< 480 && RandNum < 5){
caught = true;
}
if(strength*health >= 440 && strength*health< 460 && RandNum < 7){
caught = true;
}
if(strength*health >= 420 && strength*health< 440 && RandNum < 10){
caught = true;
}
if(strength*health >= 400 && strength*health< 420 && RandNum < 12){
caught = true;
}
if(strength*health >= 380 && strength*health< 400 && RandNum < 14){
caught = true;
}
if(strength*health >= 360 && strength*health< 380 && RandNum < 16){
caught = true;
}
if(strength*health >= 340 && strength*health< 360 && RandNum < 17){
caught = true;
}
if(strength*health >= 320 && strength*health< 340 && RandNum < 19){
caught = true;
}
if(strength*health >= 300 && strength*health< 320 && RandNum < 20){
caught = true;
}
if(strength*health >= 280 && strength*health< 300 && RandNum < 22){
caught = true;
}
if(strength*health >= 260 && strength*health< 280 && RandNum < 24){
caught = true;
}
if(strength*health >= 240 && strength*health< 260 && RandNum < 26){
caught = true;
}
if(strength*health >= 220 && strength*health< 240 && RandNum < 28){
caught = true;
}
if(strength*health >= 200 && strength*health< 220 && RandNum < 30){
caught = true;
}
if(strength*health >= 180 && strength*health< 200 && RandNum < 32){
caught = true;
}
if(strength*health >= 160 && strength*health< 180 && RandNum < 34){
caught = true;
}
if(strength*health >= 140 && strength*health< 160 && RandNum < 36){
caught = true;
}
if(strength*health >= 120 && strength*health< 140 && RandNum < 38){
caught = true;
}
if(strength*health >= 100 && strength*health< 120 && RandNum < 40){
caught = true;
}
if(strength*health >= 80 && strength*health< 100 && RandNum < 42){
caught = true;
}
if(strength*health >= 60 && strength*health< 80 && RandNum < 44){
caught = true;
}
if(strength*health >= 40 && strength*health< 60 && RandNum < 46){
caught = true;
}
if(strength*health >= 20 && strength*health< 40 && RandNum < 48){
caught = true;
}
if(strength*health >= 0 && strength*health< 20 && RandNum < 50){
caught = true;
}
//I Want to add the caught monster to a list here
if(caught == true && !once){
print("You Caught A " + Monster.name);
Monster.gameObject.active = false;
once = true;
}
if(caught == false){
Monster.gameObject.active = true;
print("The " + Monster.name + " escaped!");
Destroy(gameObject);
}
}
}
function OnTriggerEnter(other : Collider){
if(other.tag == "Monster"){
other.gameObject.active = false;
rigidbody.isKinematic = true;
Enemyscript = other.GetComponent("Enemy");
Healthscript = other.GetComponent("Health");
strength = Enemyscript.strength;
health = Healthscript.health;
Monster = other.gameObject;
if(health*strength >500){
print("The " + Monster.name + " is to strong!");
other.gameObject.active = true;
Destroy(gameObject);
}
if(health*strength <= 500){
catchable = true;
other.gameObject.active = false;
}
}
}
↧