This repository has been archived on 2025-04-11. You can view files and clone it, but cannot push or open issues or pull requests.
mochapine64backup/MoCha/Assets/Scripts/MonsterManager.cs

60 lines
1.8 KiB
C#
Raw Normal View History

2018-04-17 13:55:28 -05:00
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.Text;
using UnityEngine.SceneManagement;
public class MonsterManager : MonoBehaviour {
2018-04-23 18:49:34 -05:00
public GameObject inventory;
public Item item;
2018-04-17 13:55:28 -05:00
2018-04-24 13:49:36 -05:00
public Inventory inv;
2018-04-23 18:49:34 -05:00
void Start()
{
2018-04-26 06:59:29 -05:00
loadMonster();
2018-04-23 18:49:34 -05:00
}
public void showItems()
{
if (inventory.activeSelf == false)
inventory.SetActive (true);
else inventory.SetActive (false);
2018-04-19 14:16:56 -05:00
}
2018-04-23 18:49:34 -05:00
public void saveMonster()
2018-04-17 13:55:28 -05:00
{
2018-04-25 23:16:28 -05:00
GameObject[] monsterParts = GameObject.FindGameObjectsWithTag("MonsterPart");
StringBuilder pos = new StringBuilder ();
string savedString;
2018-04-26 06:59:29 -05:00
string equippedString = "";
2018-04-25 23:16:28 -05:00
for (int i = 0; i < monsterParts.Length; i++) {
pos = new StringBuilder ();
pos.Append(GameObject.Find(monsterParts[i].name).transform.position.x).Append(" ").Append(GameObject.Find(monsterParts[i].name).transform.position.y).Append(" ").Append(GameObject.Find(monsterParts[i].name).transform.position.z);
2018-04-26 06:59:29 -05:00
equippedString = equippedString + monsterParts [i].name + " ";
2018-04-25 23:16:28 -05:00
savedString = pos.ToString ();
PlayerPrefs.SetString(/*SceneManager.GetActiveScene().name + */monsterParts[i].name, savedString);
2018-04-25 23:16:28 -05:00
}
2018-04-26 06:59:29 -05:00
PlayerPrefs.SetString ("Equipped", equippedString);
2018-04-17 13:55:28 -05:00
}
public void loadMonster ()
{
2018-04-26 06:59:29 -05:00
string equippedString = PlayerPrefs.GetString("Equipped");
string[] equipped = equippedString.Split (' ');
for (int i = 0; i < equipped.Length - 1; i++) {
string savedString = PlayerPrefs.GetString(/*SceneManager.GetActiveScene().name + */equipped[i]);
2018-04-26 06:59:29 -05:00
string[] values = savedString.Split ();
GameObject instance = (GameObject)Instantiate(Resources.Load(equipped[i]));
instance.name = equipped [i];
instance.GetComponent<DragAndDrop> ().inventory = inv;
instance.transform.position = new Vector3(float.Parse(values[0]),float.Parse(values[1]),float.Parse(values[2]));
}
2018-04-17 13:55:28 -05:00
}
}