You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
PlumberUltimateAds/Assets/Prefab/instantiate prefab.cs

207 lines
5.3 KiB
C#

using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using UnityEngine;
using UnityEngine.UI;
using System;
public class instantiateprefab : MonoBehaviour
{
public GameObject panel;
public Button TAdsbutton;
public Slider SliderPrefabSpawner;
public Transform ParentOfLayout;
public List<LevelGroup> levelGroups;
public int numberOfInstances = 9;
public int minIndex = 0;
public int maxIndex = 8;
public int points;
public string pointtext;
public AchievementManager manger;
public ScoreButton score;
public GameManager gameManager;
private List<Slider> sliders = new List<Slider>();
public GamePlayManager gameplay;
public Slider sliderprefabalue, hintcheckvalue;
private LevelGroupButton levelGroupButton;
public void Awake()
{
levelGroupButton=GetComponent<LevelGroupButton>();
}
void Start()
{
InstantiatePrefabsInLayoutGroup();
}
/* private void InstantiateSlider(int index, Vector3 position)
{
GameObject sliderObject = Instantiate(prefab, position, Quaternion.identity, ParentOfLayout);
sliderObject.GetComponent<ScoreButton>().myIndex = index + 1;
foreach (Transform child in sliderObject.transform)
{
if (child.name == Mode)
{
Text levelname = child.GetComponent<Text>();
levelname.text = manger.AchievementList[index].DisplayName.ToString();
}
if (child.name == pointtext)
{
Text progress = child.GetComponent<Text>();
progress.text = manger.AchievementList[index].ProgressGoal + " / " + manger.AchievementList[index].ProgressSuffix.ToString();
}
}
Slider slider = sliderObject.GetComponent<Slider>();
if (slider != null)
{
slider.minValue = 0;
slider.maxValue = levelGroups[index].TotalLevel;
slider.value = levelGroups[index].CompletedLevel;
sliders.Add(slider); // Store the slider in the list
}
}*/
public void Watch10AdsButton()
{
if (sliders.Count > 6)
{
Slider TenAds = sliders[6];
TenAds.value += 1;
TenAds.maxValue = 10;
TenAds.minValue = 0;
}
}
public void Watch20Adsutton()
{
if (sliders.Count > 7)
{
Slider TwentyAds = sliders[7];
TwentyAds.value += 1;
TwentyAds.maxValue = 20;
TwentyAds.minValue = 0;
if(TwentyAds.value==20)
{
TwentyAds.maxValue = 20;
}
}
}
public void Update()
{
HintandPipeRotationAchivementValue();
}
public void HintandPipeRotationAchivementValue()
{
if (sliders.Count > 5)
{
Slider Hint = sliders[5];
Hint.value = hintcheckvalue.value;
Hint.maxValue = 1000;
}
if (sliders.Count > 8)
{
Slider PipeRotationvalue = sliders[8];
PipeRotationvalue.value = sliderprefabalue.value;
PipeRotationvalue.maxValue = 1000;
}
}
public void poppanel()
{
panel.SetActive(true);
}
public void MaxValueset()
{
if (sliders.Count > 7)
{
Slider twentyAds = sliders[7];
twentyAds.maxValue = 20;
if(twentyAds.value==20)
{
TAdsbutton.interactable = false;
}
}
}
public void AchivementsetFalse()
{
panel.SetActive(false);
}
/* public void ChangeTotalvalue()
{
for (int i = 0; i < sliders.Count; i++)
{
if (levelGroups[i].CompletedLevel == levelGroups[i].TotalLevel)
{
sliders[i].maxValue = levelGroups[i].TotalLevel;
// Increment the TotalLevel by 5 immediately
levelGroups[i].TotalLevel += 5;
score.completetargets += 1;
score.points += 50 * score.myIndex;
// score. targetText.text = "" + completetargets.ToString();
if (levelGroupButton != null)
{
levelGroupButton.UpdateUI();
}
}
}
}*/
private void InstantiatePrefabsInLayoutGroup()
{
for (int i = 0; i < numberOfInstances; i++)
{
Slider instance = Instantiate(SliderPrefabSpawner);
instance.transform.SetParent(ParentOfLayout, false);
instance.transform.localScale = Vector3.one;
instance.transform.localPosition = Vector3.zero;
ScoreButton scoreButton = instance.GetComponent<ScoreButton>();
if (scoreButton != null)
{
scoreButton.myIndex = i + 1;
scoreButton.levelname.text = manger.AchievementList[i].DisplayName;
}
sliders.Add(instance);
if (i < 5)
{
instance.minValue = 0;
instance.maxValue = levelGroups[i].TotalLevel;
instance.value = levelGroups[i].CompletedLevel;
}
}
}
}