Facebook
From asfasf, 3 Years ago, written in C#.
Embed
Download Paste or View Raw
Hits: 129
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class Player : MonoBehaviour
  6. {
  7.     public static Player Instance { get; private set; }
  8.  
  9.  
  10.  
  11.     public int level = 5;
  12.     public int health = 40;
  13.    
  14.    
  15.  
  16.  
  17.     [SerializeField] private UI_Inventory uiInventory;
  18.     private Inventory inventory;
  19.  
  20.  
  21.     private void Start()
  22.  
  23.  
  24.     {
  25.      
  26.         Instance = this;
  27.         inventory = new Inventory();
  28.         uiInventory.SetInventory(inventory);
  29.  
  30.  
  31.         //this is where you can spawn item in world//
  32.        
  33.     }
  34.     private void OnTriggerEnter(Collider collider)
  35.     {
  36.         ItemWorld itemWorld = collider.GetComponent<ItemWorld>();
  37.         if (itemWorld != null)
  38.         {
  39.             //Touching item
  40.             inventory.AddItem(itemWorld.GetItem());
  41.             itemWorld.DestroySelf();
  42.  
  43.  
  44.         }
  45.     }
  46.  
  47.     public void SavePlayer()
  48.     {
  49.         SaveSystem.SavePlayer(this);
  50.  
  51.  
  52.     }
  53.  
  54.  
  55.     public void LoadPlayer()
  56.     {
  57.         PlayerData data = SaveSystem.LoadPlayer();
  58.  
  59.         level = data.level;
  60.         health = data.health;
  61.        
  62.        
  63.  
  64.     transform.position = new
  65.             Vector3(PlayerPrefs.GetFloat("PlayerX"),
  66.             PlayerPrefs.GetFloat("PlayerY"),
  67.             PlayerPrefs.GetFloat("PlayerZ"));
  68.  
  69.  
  70.     }
  71.  
  72. }