mirror of
https://github.com/Leahnaya/TheKingsRace.git
synced 2026-08-21 18:04:27 -05:00
Added Item Cost and Max Points
Added Glide Added Item adding verification
This commit is contained in:
@@ -2,18 +2,25 @@ using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using UnityEngine.SceneManagement;
|
||||
|
||||
public class InvSceneSettings : MonoBehaviour
|
||||
{
|
||||
GameObject player1;
|
||||
PlayerInventory pInv;
|
||||
public GameObject itemOptPrefab;
|
||||
private Text pointText;
|
||||
private PlayerStats pStats;
|
||||
|
||||
InventoryManager invMan;
|
||||
Vector3 position;
|
||||
private int pointsLeft;
|
||||
|
||||
// Start is called before the first frame update
|
||||
void Awake(){
|
||||
player1 = GameObject.Find("PlayerPrefab");
|
||||
pStats = player1.GetComponent<PlayerStats>();
|
||||
pointText = GameObject.Find("PlayerPoints").GetComponentInChildren<Text>();
|
||||
pInv = player1.GetComponent<PlayerInventory>();
|
||||
player1.GetComponent<PlayerMovement>().enabled = false;
|
||||
player1.transform.GetChild(0).gameObject.SetActive(false);
|
||||
@@ -23,25 +30,27 @@ public class InvSceneSettings : MonoBehaviour
|
||||
|
||||
void Start(){
|
||||
InitializeItemB();
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update(){
|
||||
|
||||
pointsLeft = pStats.PlayerPoints;
|
||||
pointText.text = "Points Left: " + pointsLeft;
|
||||
}
|
||||
|
||||
private void InitializeItemB(){
|
||||
int index = 0;
|
||||
if(itemOptPrefab != null){
|
||||
foreach(Item item in invMan.ItemList){
|
||||
|
||||
Vector3 position = new Vector3((1+(index)),3,0);
|
||||
|
||||
if(index < 5){
|
||||
position = new Vector3(((index)),3,0);
|
||||
}
|
||||
else{
|
||||
position = new Vector3(((index-5)),2,0);
|
||||
}
|
||||
var iOpt = Instantiate(itemOptPrefab, position, Quaternion.identity);
|
||||
|
||||
iOpt.name = item.itemName;
|
||||
iOpt.transform.SetParent(GameObject.Find("Items").transform);
|
||||
iOpt.transform.localScale = new Vector3(1,1,1);
|
||||
iOpt.GetComponent<Button>().onClick.AddListener(delegate{pInv.AddItem(item);});
|
||||
iOpt.transform.localScale = new Vector3(1.5f,1.5f,1.5f);
|
||||
iOpt.GetComponent<Button>().onClick.AddListener(delegate{pInv.AddItem(item, UpdatePoints(item.costM, item));});
|
||||
iOpt.GetComponentInChildren<Text>().text = item.itemName;
|
||||
|
||||
//iOpt.GetComponentInChildren<Image>() = item.image; // IMPLEMENT WHEN ITEM OBJECT CONTAIN IMAGE REFERENCE
|
||||
@@ -54,4 +63,26 @@ public class InvSceneSettings : MonoBehaviour
|
||||
|
||||
}
|
||||
|
||||
private bool UpdatePoints(int itemCost, Item item){
|
||||
if(pInv.GetItems().Contains(item)){
|
||||
pointsLeft += itemCost;
|
||||
pointText.text = "Points Left: " + pointsLeft;
|
||||
return true;
|
||||
}
|
||||
else if(!pInv.GetItems().Contains(item) && (pointsLeft - itemCost) >= 0){
|
||||
pointsLeft -= itemCost;
|
||||
pointText.text = "Points Left: " + pointsLeft;
|
||||
return true;
|
||||
}
|
||||
else{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public void nextScene(){
|
||||
player1.GetComponent<PlayerMovement>().enabled = true;
|
||||
player1.transform.GetChild(0).gameObject.SetActive(true);
|
||||
SceneManager.LoadScene (SceneManager.GetActiveScene().buildIndex + 1);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user