所有任务,fungus插件进行触发函数,接任务时关闭fowchat脚本,打开下一个人的脚本,task4后返回初始,task3中要写在update中并且换音乐,打完怪要清除现有所有怪且关闭脚本
using System;
using System.Collections;
using System.Collections.Generic;
using Fungus;
using UnityEngine;
using UnityEngine.Serialization;
using UnityEngine.UI;
public class AllTask : MonoBehaviour
{
private Text _textTask;
private Text _textAward;
private HeroProperty _heroProperty;
public GameObject colliderFather;
public GameObject colliderSon;
public GameObject colliderGrandFather;
public GameObject enemyFactory;
public int enemyNum;
private SkillTree _skillTree;
private bool _task3;
private void Start()
{
_textTask = transform.GetChild(0).GetComponent<Text>();
_textAward = transform.GetChild(1).GetComponent<Text>();
_heroProperty = GameObject.FindWithTag("Property").GetComponent<HeroProperty>();
_skillTree = _heroProperty.transform.parent.GetChild(0).GetChild(6).GetComponent<SkillTree>();
}
public void Task1()
{
_textTask.text= "任务描述:\n去找卖菜老头传话";
_textAward.text = "任务奖励:\n技能点数+1\n金币+200";
colliderFather.GetComponent<Collider>().enabled=true;
colliderSon.GetComponent<Collider>().enabled=false;
}
public void Task2()
{
_heroProperty.allNum += 1;
_heroProperty.money += 200;
colliderGrandFather.GetComponent<Collider>().enabled = true;
colliderFather.GetComponent<Collider>().enabled=false;
}
public void Task3()
{
_task3 = true;
_heroProperty.allNum += 99;
_heroProperty.attack += 200;
enemyFactory.GetComponent<EnemyFactory>().enabled = true;
colliderGrandFather.GetComponent<Collider>().enabled = false;
SoundManage.Instance.PlayBgm("战斗场景2");
}
public void Task4()
{
_heroProperty.allNum = 11;
_heroProperty.attack -= 200;
_heroProperty.money += 1000;
colliderGrandFather.GetComponent<Collider>().enabled = false;
_skillTree.up2 = false;
_skillTree.up3 = false;
_skillTree.up4 = false;
_skillTree.pass2.SetActive(false);
_skillTree.pass3.SetActive(false);
_skillTree.pass4.SetActive(false);
_skillTree.btn2.GetComponent<Image>().color=Color.gray;
_skillTree.btn3.GetComponent<Image>().color=Color.gray;
_skillTree.btn4.GetComponent<Image>().color=Color.gray;
}
private void Update()
{
if (_task3)
{
_textTask.text = "任务描述:\n消灭超过50只蜘蛛精\n已消灭:"+enemyNum;
_textAward.text = "任务奖励:\n技能点数+10\n金币+1000";
}
if (enemyNum>=50)
{
_task3 = false;
colliderGrandFather.GetComponent<Collider>().enabled = true;
enemyFactory.GetComponent<EnemyFactory>().enabled = false;
GameObject[] obj = GameObject.FindGameObjectsWithTag("Enemy");
for (int i = 0; i < obj.Length; i++)
{
Destroy(obj[i]);
}
SoundManage.Instance.PlayBgm("揽仙镇");
}
}
}
伤害文字, 开始的时候延迟2s销毁,并且执行向上移动过,始终看向摄像机 ,并且写个重载方法text的内容为传入的伤害值
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class AttackText : MonoBehaviour
{
public Text _text;
private void Start()
{
Destroy(gameObject,1);
}
private void Update()
{
transform.LookAt(Camera.main.transform);
transform.position+=new Vector3(0,2*Time.deltaTime,0);
}
public void ShowDamage(int amount)
{
_text.text = amount.ToString();
}
}
背包拖动 刚开始的时候设置根物体 点下去的时候记录初始父物体,并且关闭其射线检测,拖拽的过程中,位置跟着鼠标移动,拖拽结束后检测父物体,如果父物体为一系列,则返回原来,然后switch 进行交换和 移动 最后结束的时候打开射线检测
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;
public class BagTest : MonoBehaviour,IDragHandler,IBeginDragHandler,IEndDragHandler
{
//根物体
private Transform _drugParent;
//刚开始的父物体
private Transform _originalParent;
private void Start()
{
//设为根物体
_drugParent = transform.root;
}
public void OnBeginDrag(PointerEventData eventData)
{
//鼠标点下去的时候记录的父物体为初始父物体
_originalParent = transform.parent;
//然后给图片换位根物体
transform.SetParent(_drugParent);
//按下的时候将其改为射线检测不到他
transform.GetComponent<CanvasGroup>().blocksRaycasts = false;
}
public void OnDrag(PointerEventData eventData)
{
//位置跟随鼠标移动
transform.position = eventData.position;
}
public void OnEndDrag(PointerEventData eventData)
{
Debug.Log(eventData.pointerEnter.tag);
//拖拽结束时当检测到的物体为**
if (eventData.pointerEnter==null||eventData.pointerEnter.name=="Panel"||
eventData.pointerEnter.name=="Text"||eventData.pointerEnter.name=="title"||
eventData.pointerEnter.name=="Bag"|| eventData.pointerEnter.name=="Viewport"||
eventData.pointerEnter.name=="Button"||eventData.pointerEnter.name=="Property"||
eventData.pointerEnter.name=="Image"||eventData.pointerEnter.CompareTag("Text")||
eventData.pointerEnter.CompareTag("Bagequip")||eventData.pointerEnter.CompareTag("introduction")||
eventData.pointerEnter.transform.parent.CompareTag("Bagequip")||
eventData.pointerEnter.CompareTag("shop")||eventData.pointerEnter.name=="HeadPicture")
{
//设置图片的父物体为初始父物体
transform.SetParent(_originalParent);
//位置归零
transform.localPosition = Vector2.zero;
}
//将检测到的物体的标签进行分类
switch (eventData.pointerEnter.tag)
{
case "cell":
//改变父物体
transform.SetParent(eventData.pointerEnter.transform);
transform.localPosition = Vector2.zero;
break;
case "image":
//交换父物体
transform.SetParent(eventData.pointerEnter.transform.parent);
transform.localPosition = Vector2.zero;
eventData.pointerEnter.transform.SetParent(_originalParent);
eventData.pointerEnter.transform.localPosition = Vector2.zero;
break;
}
transform.GetComponent<CanvasGroup>().blocksRaycasts = true;
}
}
cd显示,开始的时候在背包里找是否有血和蓝,如果有的话就打开按钮,且图片填充为零,如果技能已经升级,则把他的颜色调亮且技能不在cd中,update中时刻检测血蓝,如果有的话 按钮是中国可以点击,当血蓝按钮关闭时则调整图片填充为1
当技能再cd中,图片填充和文字都慢慢变化,当其为零时,则调整其文字为空,且不在cd,将其与背包中的血蓝相互遍历,得到的数字为血蓝下标
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class CdShow : MonoBehaviour
{
private Transform _bagTf;
private Transform _player;
private Animator _animator;
private HeroProperty _heroProperty;
private SkillTree _skillTree;
public GameObject effhp;
public GameObject effmp;
//skill1
private Image _imageskill1;
private Text _textskill1;
public bool cdskill1;
private Button _btnskill1;
private float _cdTimerskill1;
public int needMp1;
//skill2
private Image _imageskill2;
private Text _textskill2;
public bool cdskill2;
private Button _btnskill2;
private float _cdTimerskill2 = 3;
public int needMp2=10;
//skill3
private Image _imageskill3;
private Text _textskill3;
public bool cdskill3;
private Button _btnskill3;
private float _cdTimerskill3 = 5;
public int needMp3=20;
//skill4
private Image _imageskill4;
private Text _textskill4;
public bool cdskill4;
private Button _btnskill4;
private float _cdTimerskill4 = 7;
public int needMp4=30;
//hp
public Image _imagehp;
private Text _texthp;
public bool cdhp;
public Button _btnhp;
private float _cdTimerhp = 1;
//mp
public Image _imagemp;
private Text _textmp;
public bool cdmp;
public Button _btnmp;
private float _cdTimermp = 1;
private void Start()
{
_bagTf = transform.parent.GetChild(2).GetChild(2).GetChild(0).GetChild(0);
_player = GameObject.FindWithTag("Player").transform;
_animator = GameObject.FindWithTag("Player").transform.GetChild(0).GetComponent<Animator>();
_heroProperty = GameObject.FindWithTag("Property").GetComponent<HeroProperty>();
_skillTree = _heroProperty.transform.parent.GetChild(0).GetChild(6).GetComponent<SkillTree>();
//skill1
_btnskill1= transform.GetChild(0).GetChild(0).GetChild(0).GetComponent<Button>();
_imageskill1 = transform.GetChild(0).GetChild(0).GetChild(0).GetComponent<Image>();
_textskill1 = transform.GetChild(0).GetChild(0).GetChild(0).GetChild(0).GetComponent<Text>();
_imageskill1.fillAmount = 0;
//skill2
_btnskill2= transform.GetChild(1).GetChild(0).GetChild(0).GetComponent<Button>();
_imageskill2 = transform.GetChild(1).GetChild(0).GetChild(0).GetComponent<Image>();
_textskill2 = transform.GetChild(1).GetChild(0).GetChild(0).GetChild(0).GetComponent<Text>();
_imageskill2.fillAmount = 0;
//skill3
_btnskill3= transform.GetChild(2).GetChild(0).GetChild(0).GetComponent<Button>();
_imageskill3 = transform.GetChild(2).GetChild(0).GetChild(0).GetComponent<Image>();
_textskill3 = transform.GetChild(2).GetChild(0).GetChild(0).GetChild(0).GetComponent<Text>();
_imageskill3.fillAmount = 0;
//skill4
_btnskill4= transform.GetChild(3).GetChild(0).GetChild(0).GetComponent<Button>();
_imageskill4 = transform.GetChild(3).GetChild(0).GetChild(0).GetComponent<Image>();
_textskill4 = transform.GetChild(3).GetChild(0).GetChild(0).GetChild(0).GetComponent<Text>();
_imageskill4.fillAmount = 0;
//hp
_btnhp= transform.GetChild(4).GetChild(0).GetChild(0).GetComponent<Button>();
_imagehp = transform.GetChild(4).GetChild(0).GetChild(0).GetComponent<Image>();
_texthp = transform.GetChild(4).GetChild(0).GetChild(0).GetChild(1).GetComponent<Text>();
_imagehp.fillAmount = 1;
//mp
_btnmp= transform.GetChild(5).GetChild(0).GetChild(0).GetComponent<Button>();
_imagemp = transform.GetChild(5).GetChild(0).GetChild(0).GetComponent<Image>();
_textmp = transform.GetChild(5).GetChild(0).GetChild(0).GetChild(1).GetComponent<Text>();
_imagemp.fillAmount = 1;
//开始将血蓝其关闭
_btnhp.enabled = false;
_btnmp.enabled = false;
//检测血蓝
for (int i = 0; i < _bagTf.childCount; i++)
{
if (_bagTf.GetChild(i).childCount>0)
{
if (_bagTf.GetChild(i).GetChild(0).GetComponent<Image>().sprite.name == "29")
{
transform.GetChild(4).GetChild(0).GetChild(0).GetChild(0).GetComponent<Text>().text =
_bagTf.GetChild(i).GetChild(0).GetChild(0).GetComponent<Text>().text;
_btnhp.enabled = true;
_imagehp.fillAmount = 0;
}
}
if (_bagTf.GetChild(i).childCount>0)
{
if (_bagTf.GetChild(i).GetChild(0).GetComponent<Image>().sprite.name=="30")
{transform.GetChild(5).GetChild(0).GetChild(0).GetChild(0).GetComponent<Text>().text=
_bagTf.GetChild(i).GetChild(0).GetChild(0).GetComponent<Text>().text;
_btnmp.enabled = true;
_imagemp.fillAmount = 0;
}
}
}
//skill1
_btnskill1.onClick.AddListener(() =>
{
BtnClickSkill1();
});
//skill2
_btnskill2.onClick.AddListener(() =>
{
BtnClickSkill2();
});
//skill3
_btnskill3.onClick.AddListener(() =>
{
BtnClickSkill3();
});
//skill4
_btnskill4.onClick.AddListener(() =>
{
BtnClickSkill4();
});
//hp
_btnhp.onClick.AddListener(() =>
{
BtnClickHp();
});
//mp
_btnmp.onClick.AddListener(() =>
{
BtnClickMp();
});
if (_skillTree.up2)
{
transform.GetChild(1).GetChild(0).GetComponent<Image>().color=Color.white;
cdskill2 = false;
}
if (_skillTree.up3)
{
transform.GetChild(2).GetChild(0).GetComponent<Image>().color=Color.white;
cdskill3 = false;
}
if (_skillTree.up4)
{
transform.GetChild(3).GetChild(0).GetComponent<Image>().color=Color.white;
cdskill4 = false;
}
}
private void Update()
{
for (int i = 0; i < _bagTf.childCount; i++)
{
if (_bagTf.GetChild(i).childCount>0)
{
if (_bagTf.GetChild(i).GetChild(0).GetComponent<Image>().sprite.name == "29")
{
transform.GetChild(4).GetChild(0).GetChild(0).GetChild(0).GetComponent<Text>().text =
_bagTf.GetChild(i).GetChild(0).GetChild(0).GetComponent<Text>().text;
if (cdhp==false)
{
_btnhp.enabled = true;
_imagehp.fillAmount = 0;
}
else
{
_btnhp.enabled = false;
}
}
if (_bagTf.GetChild(i).GetChild(0).GetComponent<Image>().sprite.name=="30")
{
transform.GetChild(5).GetChild(0).GetChild(0).GetChild(0).GetComponent<Text>().text=
_bagTf.GetChild(i).GetChild(0).GetChild(0).GetComponent<Text>().text;
if (cdmp==false)
{
_btnmp.enabled = true;
_imagemp.fillAmount = 0;
}
else
{
_btnmp.enabled = false;
}
}
}
}
//技能转动
if (Input.GetKeyDown(KeyCode.U))
{
BtnClickSkill2();
}
if (Input.GetKeyDown(KeyCode.I))
{
BtnClickSkill3();
}
if (Input.GetKeyDown(KeyCode.O))
{
BtnClickSkill4();
}
if (Input.GetKeyDown(KeyCode.J))
{
BtnClickSkill1();
}
//skill1
if (cdskill1)
{
_imageskill1.fillAmount -= Time.deltaTime / _cdTimerskill1;
_textskill1.text = ((int) (_imageskill1.fillAmount * _cdTimerskill1)).ToString();
_imageskill1.fillAmount = Mathf.Clamp(_imageskill1.fillAmount, 0, 1);
if (_imageskill1.fillAmount<=0)
{
_textskill1.text=String.Empty;
cdskill1 = false;
}
}
//skill2
if (cdskill2)
{
_imageskill2.fillAmount -= Time.deltaTime / _cdTimerskill2;
_textskill2.text = ((int) (_imageskill2.fillAmount * _cdTimerskill2)).ToString();
_imageskill2.fillAmount = Mathf.Clamp(_imageskill2.fillAmount, 0, 1);
if (_imageskill2.fillAmount<=0)
{
_textskill2.text=String.Empty;
cdskill2 = false;
}
}
//skill3
if (cdskill3)
{
_imageskill3.fillAmount -= Time.deltaTime / _cdTimerskill3;
_textskill3.text = ((int) (_imageskill3.fillAmount * _cdTimerskill3)).ToString();
_imageskill3.fillAmount = Mathf.Clamp(_imageskill3.fillAmount, 0, 1);
if (_imageskill3.fillAmount<=0)
{
_textskill3.text=String.Empty;
cdskill3 = false;
}
}
//skill4
if (cdskill4)
{
_imageskill4.fillAmount -= Time.deltaTime / _cdTimerskill4;
_textskill4.text = ((int) (_imageskill4.fillAmount * _cdTimerskill4)).ToString();
_imageskill4.fillAmount = Mathf.Clamp(_imageskill4.fillAmount, 0, 1);
if (_imageskill4.fillAmount<=0)
{
_textskill4.text=String.Empty;
cdskill4 = false;
}
}
//hp
if (cdhp)
{
_imagehp.fillAmount -= Time.deltaTime / _cdTimerhp;
_texthp.text = ((int) (_imagehp.fillAmount * _cdTimerhp)).ToString();
_imagehp.fillAmount = Mathf.Clamp(_imagehp.fillAmount, 0, 1);
if (_imagehp.fillAmount <= 0)
{
cdhp = false;
_texthp.text = String.Empty;
}
}
//mp
if (cdmp)
{
_imagemp.fillAmount -= Time.deltaTime / _cdTimermp;
_textmp.text = ((int) (_imagemp.fillAmount * _cdTimermp)).ToString();
_imagemp.fillAmount = Mathf.Clamp(_imagemp.fillAmount, 0, 1);
if (_imagemp.fillAmount <= 0)
{
cdmp = false;
_textmp.text = String.Empty;
}
}
if (_skillTree.up2)
{
transform.GetChild(1).GetChild(0).GetComponent<Image>().color=Color.white;
}
if (_skillTree.up3)
{
transform.GetChild(2).GetChild(0).GetComponent<Image>().color=Color.white;
}
if (_skillTree.up4)
{
transform.GetChild(3).GetChild(0).GetComponent<Image>().color=Color.white;
}
if (_btnmp.enabled==false&&cdmp)
{
}
}
//skill1
public void BtnClickSkill1()
{
if (cdskill1==false)
{
_imageskill1.fillAmount = 1;
_animator.SetTrigger("attack1");
cdskill1 = true;
Debug.Log("德玛西亚1");
}
else
{
Debug.Log("技能正在冷却1...");
}
}
//skill2
public void BtnClickSkill2()
{
if (_heroProperty.mp<needMp2||_skillTree.up2==false||
_animator.GetCurrentAnimatorStateInfo(1).IsTag("attack"))
{
return;
}
if (cdskill2==false)
{
_imageskill2.fillAmount = 1;
_animator.SetTrigger("attack2");
cdskill2 = true;
Debug.Log("德玛西亚2");
}
else
{
Debug.Log("技能正在冷却2...");
}
}
//skill3
public void BtnClickSkill3()
{
if (_heroProperty.mp<needMp3||_skillTree.up3==false||_animator.GetCurrentAnimatorStateInfo(1).IsTag("attack"))
{
return;
}
if (cdskill3==false)
{
_imageskill3.fillAmount = 1;
_animator.SetTrigger("attack3");
cdskill3 = true;
Debug.Log("德玛西亚3");
}
else
{
Debug.Log("技能正在冷却3...");
}
}
//skill4
public void BtnClickSkill4()
{
if (_heroProperty.mp<needMp3||_skillTree.up4==false||_animator.GetCurrentAnimatorStateInfo(1).IsTag("attack"))
{
return;
}
if (cdskill4==false)
{
_imageskill4.fillAmount = 1;
_animator.SetTrigger("attack4");
cdskill4 = true;
Debug.Log("德玛西亚4");
}
else
{
Debug.Log("技能正在冷却4...");
}
}
//hp
public void BtnClickHp()
{
if (_player==null)
{
return;
}
GameObject obj = Instantiate(effhp, _player.position, Quaternion.identity,_player);
_animator.SetTrigger("hpmp");
Destroy(obj,3f);
if (cdhp==false)
{
_imagehp.fillAmount = 1;
cdhp = true;
Debug.Log("德玛西亚");
}
else
{
Debug.Log("技能正在冷却...");
}
if (transform.GetChild(4).GetChild(0).GetChild(0).GetChild(0).GetComponent<Text>().text==String.Empty)
{
_imagehp.fillAmount = 1;
_btnhp.enabled = false;
}
}
//mp
public void BtnClickMp()
{
if (_player==null)
{
return;
}
GameObject obj = Instantiate(effmp, _player.position, Quaternion.identity,_player);
Destroy(obj,3f);
_animator.SetTrigger("hpmp");
if (cdmp==false)
{
_imagemp.fillAmount = 1;
cdmp = true;
Debug.Log("德玛西亚");
}
else
{
Debug.Log("技能正在冷却...");
}
if (transform.GetChild(5).GetChild(0).GetChild(0).GetChild(0).GetComponent<Text>().text==String.Empty)
{
_imagemp.fillAmount = 1;
_btnmp.enabled = false;
}
}
}
onmouse 声明一个事件 和 射线检测 射线检测进行存储 检测事件的位置为鼠标的坐标下的位置 将其存储到list中,然后进行判断,当list列表第一位不为空且名字为cd血蓝的时候,当期按钮关闭的时候将其返回,血和蓝假的量为自己的量且不能超过目前的最高值,如果list0为空的时候将遍历到的那个血蓝销毁,当大于零的时后就减一
获取图片的名字,图片的名字为装备类的名字,调整创建的面板的位置,根据图片的名字将装备得到信息传入到信息面板中,然后检测如果下去的那个物体是商店物体,就激活购买的按钮进行判断,如果背包里的钱小于物品的钱就退出,大于就直接购买,便且减少钱数
下装备的时候 套用商场买东西的方法,遍历父物体的子物体数的,当他的下表为空时销毁,当他的下标大于一时减一,
吃药的话也是一样的,加的的最高血量为最大血量数,为空就销毁,不为空就减一
穿衣服的话当点击按钮的时候进行switch判断图片的名字,当是0的时候,判断身上的第一个格子是否有子物体,如果有子物体的话判断两个是否一样,一样就换,不一样就不换,如果没柚子物体,直接穿上,且背包里的物体减一,因为背包里还又两个物体是加攻击的,这时需要判断另外零个物体是否存在,存在的话攻击力就为其他两个的攻击力之和再加这个物体的狗攻击力,否则就为100初始攻击力加上武器的攻击力,刷新文本
当为1的时候,现有的mp的基础开始算,第六个篮子也是影响蓝的,所以进行判断, 五有二有,五有二无,五无二有,五无二无,分这四种情况进行判断,第一种的时候总血量就为初始的血量加上五装备的血量,加上要穿的这个血量,当前的血量则为这个血量加上五的血量和要穿的血量,第二种情况是直接算自己要穿的装备的血量加初始,加要穿的血量,第三个情况是替换,第四种情况是直接穿自己的血量加初始血量,然后进行图片替换和增减,用到下面的替换方法,下面的格子都是一样的替换方法
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;
using System.Collections;
using System.Collections.Generic;
using Fungus;
//检测UI
public class OnMouse : MonoBehaviour
{
private Equipment _equipment;
public List<RaycastResult> list;
private int num;
public GameObject panelObj;
private GameObject panel;
public GameObject meun;
private ShopTest _shopTest;
private HeroProperty _heroProperty;
public GameObject itemPre;
private PlayerDamage _playerDamage;
private CdShow _cdShow;
void Start() {
list = new List<RaycastResult>();
_equipment = GameObject.FindWithTag("GameController").GetComponent<Equipment>();
_shopTest=GameObject.FindWithTag("WeaponStore").GetComponent<ShopTest>();
_heroProperty = GameObject.FindWithTag("Property").GetComponent<HeroProperty>();
_playerDamage = GameObject.FindWithTag("Player").GetComponent<PlayerDamage>();
_cdShow = _heroProperty.transform.parent.GetChild(0).GetChild(0).GetComponent<CdShow>();
}
void Update()
{
if (Input.GetMouseButtonDown(0))
{
list = GraphicRaycaster(Input.mousePosition);
if (list.Count<=0)
{
return;
}
//删除面板
if (panel!=null&&list[0].gameObject.tag!="Buy"&&list[0].gameObject.tag!="Sell"&&
list[0].gameObject.tag!="introduction"&&list[0].gameObject.tag!="Use")
{
Destroy(panel);
}
//cd嗑药
if (list[0].gameObject!=null&&(list[0].gameObject.name=="cdmpText"||list[0].gameObject.name=="cdhpText"))
{
if (list[0].gameObject.transform.parent.GetComponent<Button>().enabled==false)
return;
int nameNum=int.Parse(list[0].gameObject.transform.parent.GetComponent<Image>().sprite.name);
_heroProperty.hp += _equipment.equips[nameNum].hp;
if (_heroProperty.hp>_heroProperty.allHp)
{
_heroProperty.hp = _heroProperty.allHp;
}
_heroProperty.mp += _equipment.equips[nameNum].mp;
if (_heroProperty.mp>_heroProperty.allMp)
{
_heroProperty.mp = _heroProperty.allMp;
}
if (list[0].gameObject.transform.parent.GetChild(0).GetComponent<Text>().text == String.Empty)
{
Transform _bagTf1 = transform.GetChild(0).GetChild(2).GetChild(2).GetChild(0).GetChild(0);
for (int i = 0; i < _bagTf1.childCount; i++)
{
if (_bagTf1.GetChild(i).childCount > 0 &&
_bagTf1.GetChild(i).GetChild(0).GetComponent<Image>().sprite.name == "29")
{
if (list[0].gameObject.name == "cdhpText")
{
Destroy(_bagTf1.GetChild(i).gameObject);
}
}
if (_bagTf1.GetChild(i).childCount > 0 &&
_bagTf1.GetChild(i).GetChild(0).GetComponent<Image>().sprite.name == "30")
{
if (list[0].gameObject.name == "cdmpText")
{
Destroy(_bagTf1.GetChild(i).gameObject);
}
}
}
}
else if (int.Parse(list[0].gameObject.transform.parent.GetChild(0).GetComponent<Text>().text) > 1)
{
Transform _bagTf = transform.GetChild(0).GetChild(2).GetChild(2).GetChild(0).GetChild(0);
for (int i = 0; i < _bagTf.childCount; i++)
{
if (_bagTf.GetChild(i).childCount>0&&_bagTf.GetChild(i).GetChild(0).GetComponent<Image>().sprite.name=="29")
{
if (list[0].gameObject.name=="cdhpText")
{
_bagTf.GetChild(i).GetChild(0).GetChild(0).GetComponent<Text>().text=
(int.Parse(_bagTf.GetChild(i).GetChild(0).GetChild(0).GetComponent<Text>().text) - 1).ToString();
if (int.Parse(_bagTf.GetChild(i).GetChild(0).GetChild(0).GetComponent<Text>().text)==1)
{
_bagTf.GetChild(i).GetChild(0).GetChild(0).GetComponent<Text>().text=String.Empty;
}
}
}
if (_bagTf.GetChild(i).childCount>0&&_bagTf.GetChild(i).GetChild(0).GetComponent<Image>().sprite.name=="30")
{
if (list[0].gameObject.name=="cdmpText")
{
_bagTf.GetChild(i).GetChild(0).GetChild(0).GetComponent<Text>().text=
(int.Parse(_bagTf.GetChild(i).GetChild(0).GetChild(0).GetComponent<Text>().text) - 1).ToString();
if (int.Parse(_bagTf.GetChild(i).GetChild(0).GetChild(0).GetComponent<Text>().text)==1)
{
_bagTf.GetChild(i).GetChild(0).GetChild(0).GetComponent<Text>().text=String.Empty;
}
}
}
}
}
}
if (list[0].gameObject!=null&&(list[0].gameObject.CompareTag("shop")||list[0].gameObject.CompareTag("image")))
{
//创建面板
num=int.Parse(list[0].gameObject.GetComponent<Image>().sprite.name);
panel = Instantiate(panelObj, transform.position,panelObj.transform.rotation);
panel.transform.SetParent(transform);
//调面板位置
if (list[0].gameObject.CompareTag("shop"))
{
if (Input.mousePosition.y<500)
{
panel.transform.position =
new Vector3(Input.mousePosition.x+300,Input.mousePosition.y+500,Input.mousePosition.z);
}
else
{
panel.transform.position =
new Vector3(Input.mousePosition.x+300,Input.mousePosition.y-80,Input.mousePosition.z);
}
}
if (list[0].gameObject.CompareTag("image"))
{
if (Input.mousePosition.y<500)
{
panel.transform.position =
new Vector3(Input.mousePosition.x-50,Input.mousePosition.y+500,Input.mousePosition.z);
}
else
{
panel.transform.position =
new Vector3(Input.mousePosition.x-50,Input.mousePosition.y-80,Input.mousePosition.z);
}
}
//获取图片
Sprite sp = list[0].gameObject.GetComponent<Image>().sprite;
GameObject spp = list[0].gameObject;
panel.transform.GetChild(1).GetComponent<Text>().text = _equipment.equips[num].id.ToString();
panel.transform.GetChild(2).GetComponent<Text>().text = _equipment.equips[num].name;
panel.transform.GetChild(3).GetComponent<Text>().text = _equipment.equips[num].hp.ToString();
panel.transform.GetChild(4).GetComponent<Text>().text = _equipment.equips[num].mp.ToString();
panel.transform.GetChild(5).GetComponent<Text>().text = _equipment.equips[num].attack.ToString();
panel.transform.GetChild(6).GetComponent<Text>().text = _equipment.equips[num].speed.ToString();
panel.transform.GetChild(7).GetComponent<Text>().text = _equipment.equips[num].describe;
panel.transform.GetChild(8).GetComponent<Text>().text = _equipment.equips[num].buy.ToString();
panel.transform.GetChild(9).GetComponent<Text>().text = _equipment.equips[num].sell.ToString();
//检测商店
if (list[0].gameObject.CompareTag("shop"))
{
panel.transform.GetChild(10).GetComponent<Button>().onClick.AddListener(() =>
{
if (_heroProperty.money<_equipment.equips[num].buy)
{
Debug.Log("买不起");
return;
}
_shopTest.btnOnClick(sp);
_heroProperty.money -= _equipment.equips[num].buy;
Destroy(panel);
//_heroProperty.AddCheckProperty();
_heroProperty._textmoney.text = _heroProperty.money.ToString();
});
}
//卸下装备
if (list[0].gameObject.CompareTag("image")&&list[0].gameObject.transform.parent.CompareTag("Bagequip"))
{
panel.transform.GetChild(13).GetComponent<Button>().onClick.AddListener(() =>
{
Destroy(panel);
Destroy(spp);
_shopTest.btnOnClick(sp);
});
}
//卖装备
if (list[0].gameObject.CompareTag("image")&&list[0].gameObject.transform.parent.CompareTag("cell"))
{
panel.transform.GetChild(11).GetComponent<Button>().onClick.AddListener(() =>
{
_heroProperty.money += _equipment.equips[num].sell;
Destroy(panel);
if (spp.transform.childCount>0)
{
if (spp.transform.GetChild(0).GetComponent<Text>().text==String.Empty||
int.Parse(spp.transform.GetChild(0).GetComponent<Text>().text)==1)
{
Destroy(spp);
}
else if (int.Parse(spp.transform.GetChild(0).GetComponent<Text>().text)>1)
{
spp.transform.GetChild(0).GetComponent<Text>().text =
(int.Parse(spp.transform.GetChild(0).GetComponent<Text>().text) - 1).ToString();
if (int.Parse(spp.transform.GetChild(0).GetComponent<Text>().text) ==1)
{
spp.transform.GetChild(0).GetComponent<Text>().text = string.Empty;
}
}
}
//_heroProperty.AddCheckProperty();
_heroProperty._textmoney.text = _heroProperty.money.ToString();
});
}
//嗑药
if (_equipment.equips[num].id==7)
{
panel.transform.GetChild(12).GetComponent<Button>().onClick.AddListener(() =>
{
_playerDamage.onOffHp = true;
_playerDamage.onOffMp = true;
if (spp==null)
{
return;
}
_heroProperty.hp += _equipment.equips[num].hp;
if (_heroProperty.hp>_heroProperty.allHp)
{
_heroProperty.hp = _heroProperty.allHp;
}
_heroProperty.mp += _equipment.equips[num].mp;
if (_heroProperty.mp>_heroProperty.allMp)
{
_heroProperty.mp = _heroProperty.allMp;
}
if (spp.transform.childCount > 0)
{
if (spp.transform.GetChild(0).GetComponent<Text>().text == String.Empty)
{
Destroy(spp);
}
else if (int.Parse(spp.transform.GetChild(0).GetComponent<Text>().text) > 1)
{
spp.transform.GetChild(0).GetComponent<Text>().text =
(int.Parse(spp.transform.GetChild(0).GetComponent<Text>().text) - 1).ToString();
if (int.Parse(spp.transform.GetChild(0).GetComponent<Text>().text) == 1)
{
spp.transform.GetChild(0).GetComponent<Text>().text = string.Empty;
}
}
}
});
}
//穿衣服
if (list[0].gameObject.CompareTag("image"))
{
panel.transform.GetChild(12).GetComponent<Button>().onClick.AddListener(() =>
{
switch (_equipment.equips[num].id)
{
case 0:
if (_heroProperty.transform.GetChild(7).childCount>0)
{
_heroProperty.attack =
100 + _equipment
.equips[
int.Parse(_heroProperty.transform.GetChild(6).GetChild(0)
.GetComponent<Image>().sprite.name)].attack+ _equipment.equips[int.Parse(_heroProperty.transform.GetChild(7).
GetChild(0).GetComponent<Image>().sprite.name)].attack;
}
else if (_heroProperty.transform.GetChild(6).childCount>0)
{
_heroProperty.attack =
100 + _equipment
.equips[
int.Parse(_heroProperty.transform.GetChild(6).GetChild(0)
.GetComponent<Image>().sprite.name)].attack;
}
if (_heroProperty.transform.GetChild(0).childCount>0)
{
Sprite spP = _heroProperty.transform.GetChild(0).GetChild(0).GetComponent<Image>()
.sprite;
if (sp.name==spP.name) return;
TestChange(spp);
_shopTest.btnOnClick(spP);
_heroProperty.transform.GetChild(0).GetChild(0).GetComponent<Image>().sprite = sp;
}
else
{
GameObject item0 = Instantiate(itemPre, _heroProperty.transform);
item0.transform.SetParent(_heroProperty.transform.GetChild(0));
item0.transform.localPosition=Vector3.zero;
item0.GetComponent<Image>().sprite = sp;
TestChange(spp);
}
_heroProperty.attack += _equipment.equips[num].attack;
_heroProperty._textattack.text = _heroProperty.attack.ToString();
break;
case 1:
_heroProperty.mp = _heroProperty.mp > 100 ? 100 : _heroProperty.mp;
if (_heroProperty.transform.GetChild(5).childCount>0&&_heroProperty.transform.GetChild(1).childCount<=0)
{
_heroProperty.allMp = _equipment.equips[int.Parse(_heroProperty.transform.GetChild(5).GetChild(0)
.GetComponent<Image>().sprite.name)].mp+100+_equipment.equips[num].mp;
_heroProperty.mp += _equipment.equips[int.Parse(_heroProperty.transform.GetChild(5).GetChild(0)
.GetComponent<Image>().sprite.name)].mp+_equipment.equips[num].mp;
}
if (_heroProperty.transform.GetChild(5).childCount>0&&_heroProperty.transform.GetChild(1).childCount>0)
{
_heroProperty.mp += _equipment.equips[int.Parse(_heroProperty.transform.GetChild(5).GetChild(0)
.GetComponent<Image>().sprite.name)].mp+_equipment.equips[num].mp;
//_heroProperty.allHp = 0;
_heroProperty.allMp = _equipment.equips[int.Parse(_heroProperty.transform.GetChild(5).GetChild(0)
.GetComponent<Image>().sprite.name)].mp+100+_equipment.equips[num].mp;
}
if (_heroProperty.transform.GetChild(5).childCount<=0&&_heroProperty.transform.GetChild(1).childCount<=0)
{
_heroProperty.mp += _equipment.equips[num].mp;
_heroProperty.allMp += _equipment.equips[num].mp;
}
if (_heroProperty.transform.GetChild(5).childCount<=0&&_heroProperty.transform.GetChild(1).childCount>0)
{
_heroProperty.mp += _equipment.equips[num].mp;
_heroProperty.allMp+= _equipment.equips[num].mp-_equipment.equips
[int.Parse(_heroProperty.transform.GetChild(1).GetChild(0).GetComponent<Image>()
.sprite.name)].mp;
}
if (_heroProperty.transform.GetChild(1).childCount>0)
{
Sprite spP = _heroProperty.transform.GetChild(1).GetChild(0).GetComponent<Image>()
.sprite;
if (sp.name==spP.name) return;
_shopTest.btnOnClick(spP);
TestChange(spp);
_heroProperty.transform.GetChild(1).GetChild(0).GetComponent<Image>().sprite = sp;
}
else
{
GameObject item1 = Instantiate(itemPre, _heroProperty.transform);
item1.transform.SetParent(_heroProperty.transform.GetChild(1));
item1.transform.localPosition=Vector3.zero;
item1.GetComponent<Image>().sprite = sp;
TestChange(spp);
}
_heroProperty._textmp.text = _heroProperty.allMp.ToString();
break;
case 2:
_heroProperty.hp = _heroProperty.hp > 200 ? 200 : _heroProperty.hp;
if (_heroProperty.transform.GetChild(4).childCount>0&&_heroProperty.transform.GetChild(2).childCount<=0)
{
_heroProperty.hp+=_equipment.equips[int.Parse(_heroProperty.transform.GetChild(4).GetChild(0)
.GetComponent<Image>().sprite.name)].hp+_equipment.equips[num].hp;
_heroProperty.allHp = _equipment.equips[int.Parse(_heroProperty.transform.GetChild(4).GetChild(0)
.GetComponent<Image>().sprite.name)].hp+200+_equipment.equips[num].hp;
}
if (_heroProperty.transform.GetChild(4).childCount>0&&_heroProperty.transform.GetChild(2).childCount>0)
{
_heroProperty.hp+=_equipment.equips[int.Parse(_heroProperty.transform.GetChild(4).GetChild(0)
.GetComponent<Image>().sprite.name)].hp+_equipment.equips[num].hp;
//_heroProperty.allHp = 0;
_heroProperty.allHp = _equipment.equips[int.Parse(_heroProperty.transform.GetChild(4).GetChild(0)
.GetComponent<Image>().sprite.name)].hp+200+_equipment.equips[num].hp;
}
if (_heroProperty.transform.GetChild(4).childCount<=0&&_heroProperty.transform.GetChild(2).childCount<=0)
{
_heroProperty.hp += _equipment.equips[num].hp;
_heroProperty.allHp += _equipment.equips[num].hp;
}
if (_heroProperty.transform.GetChild(4).childCount<=0&&_heroProperty.transform.GetChild(2).childCount>0)
{
_heroProperty.hp += _equipment.equips[num].hp;
_heroProperty.allHp+= _equipment.equips[num].hp-_equipment.equips
[int.Parse(_heroProperty.transform.GetChild(2).GetChild(0).GetComponent<Image>()
.sprite.name)].hp;
}
if (_heroProperty.transform.GetChild(2).childCount>0)
{
Sprite spP = _heroProperty.transform.GetChild(2).GetChild(0).GetComponent<Image>()
.sprite;
if (sp.name==spP.name) return;
TestChange(spp);
_shopTest.btnOnClick(spP);
_heroProperty.transform.GetChild(2).GetChild(0).GetComponent<Image>().sprite = sp;
}
else
{
GameObject item2 = Instantiate(itemPre, _heroProperty.transform);
item2.transform.SetParent(_heroProperty.transform.GetChild(2));
item2.transform.localPosition=Vector3.zero;
item2.GetComponent<Image>().sprite = sp;
TestChange(spp);
}
_heroProperty._texthp.text = (_heroProperty.allHp).ToString();
break;
case 3:
if (_heroProperty.transform.GetChild(3).childCount>0)
{
Sprite spP = _heroProperty.transform.GetChild(3).GetChild(0).GetComponent<Image>()
.sprite;
if (sp.name==spP.name) return;
TestChange(spp);
_shopTest.btnOnClick(spP);
_heroProperty.transform.GetChild(3).GetChild(0).GetComponent<Image>().sprite = sp;
}
else
{
GameObject item3 = Instantiate(itemPre, _heroProperty.transform);
item3.transform.SetParent(_heroProperty.transform.GetChild(3));
item3.transform.localPosition=Vector3.zero;
item3.GetComponent<Image>().sprite = sp;
TestChange(spp);
}
_heroProperty.speed += _equipment.equips[num].speed;
_heroProperty._texthp.text = _heroProperty.hp.ToString();
break;
case 4:
_heroProperty.hp = _heroProperty.hp > 200 ? 200 : _heroProperty.hp;
if (_heroProperty.transform.GetChild(2).childCount>0&&_heroProperty.transform.GetChild(4).childCount<=0)
{
_heroProperty.hp+=_equipment.equips[int.Parse(_heroProperty.transform.GetChild(2).GetChild(0)
.GetComponent<Image>().sprite.name)].hp+_equipment.equips[num].hp;
_heroProperty.allHp = _equipment.equips[int.Parse(_heroProperty.transform.GetChild(2).GetChild(0)
.GetComponent<Image>().sprite.name)].hp+200+_equipment.equips[num].hp;
}
if (_heroProperty.transform.GetChild(2).childCount>0&&_heroProperty.transform.GetChild(4).childCount>0)
{
_heroProperty.hp+=_equipment.equips[int.Parse(_heroProperty.transform.GetChild(2).GetChild(0)
.GetComponent<Image>().sprite.name)].hp+_equipment.equips[num].hp;
//_heroProperty.allHp = 0;
_heroProperty.allHp = _equipment.equips[int.Parse(_heroProperty.transform.GetChild(2).GetChild(0)
.GetComponent<Image>().sprite.name)].hp+200+_equipment.equips[num].hp;
}
if (_heroProperty.transform.GetChild(2).childCount<=0&&_heroProperty.transform.GetChild(4).childCount<=0)
{
_heroProperty.hp += _heroProperty.hp > 200 ? 200 : _heroProperty.hp;
_heroProperty.allHp += _equipment.equips[num].hp;
}
if (_heroProperty.transform.GetChild(2).childCount<=0&&_heroProperty.transform.GetChild(4).childCount>0)
{
_heroProperty.hp += _equipment.equips[num].hp;
_heroProperty.allHp+= _equipment.equips[num].hp-_equipment.equips
[int.Parse(_heroProperty.transform.GetChild(4).GetChild(0).GetComponent<Image>()
.sprite.name)].hp;
}
if (_heroProperty.transform.GetChild(4).childCount>0)
{
Sprite spP = _heroProperty.transform.GetChild(4).GetChild(0).GetComponent<Image>()
.sprite;
if (sp.name==spP.name) return;
TestChange(spp);
_shopTest.btnOnClick(spP);
_heroProperty.transform.GetChild(4).GetChild(0).GetComponent<Image>().sprite = sp;
}
else
{
GameObject item4 = Instantiate(itemPre, _heroProperty.transform);
item4.transform.SetParent(_heroProperty.transform.GetChild(4));
item4.transform.localPosition=Vector3.zero;
item4.GetComponent<Image>().sprite = sp;
TestChange(spp);
}
_heroProperty._texthp.text = (_heroProperty.allHp).ToString();
break;
case 5:
_heroProperty.mp = _heroProperty.mp > 100 ? 100 : _heroProperty.mp;
if (_heroProperty.transform.GetChild(1).childCount>0&&_heroProperty.transform.GetChild(5).childCount<=0)
{
_heroProperty.allMp = _equipment.equips[int.Parse(_heroProperty.transform.GetChild(1).GetChild(0)
.GetComponent<Image>().sprite.name)].mp+100+_equipment.equips[num].mp;
_heroProperty.mp += _equipment.equips[int.Parse(_heroProperty.transform.GetChild(1).GetChild(0)
.GetComponent<Image>().sprite.name)].mp+_equipment.equips[num].mp;
}
if (_heroProperty.transform.GetChild(1).childCount>0&&_heroProperty.transform.GetChild(5).childCount>0)
{
_heroProperty.mp += _equipment.equips[int.Parse(_heroProperty.transform.GetChild(1).GetChild(0)
.GetComponent<Image>().sprite.name)].mp+_equipment.equips[num].mp;
//_heroProperty.allHp = 0;
_heroProperty.allMp = _equipment.equips[int.Parse(_heroProperty.transform.GetChild(1).GetChild(0)
.GetComponent<Image>().sprite.name)].mp+100+_equipment.equips[num].mp;
}
if (_heroProperty.transform.GetChild(1).childCount<=0&&_heroProperty.transform.GetChild(5).childCount<=0)
{
_heroProperty.mp += _equipment.equips[num].mp;
_heroProperty.allMp += _equipment.equips[num].mp;
}
if (_heroProperty.transform.GetChild(1).childCount<=0&&_heroProperty.transform.GetChild(5).childCount>0)
{
_heroProperty.mp += _equipment.equips[num].mp;
_heroProperty.allMp+= _equipment.equips[num].mp-_equipment.equips
[int.Parse(_heroProperty.transform.GetChild(5).GetChild(0).GetComponent<Image>()
.sprite.name)].mp;
}
if (_heroProperty.transform.GetChild(5).childCount>0)
{
Sprite spP = _heroProperty.transform.GetChild(5).GetChild(0).GetComponent<Image>()
.sprite;
if (sp.name==spP.name) return;
TestChange(spp);
_shopTest.btnOnClick(spP);
_heroProperty.transform.GetChild(5).GetChild(0).GetComponent<Image>().sprite = sp;
}
else
{
GameObject item5 = Instantiate(itemPre, _heroProperty.transform);
item5.transform.SetParent(_heroProperty.transform.GetChild(5));
item5.transform.localPosition=Vector3.zero;
item5.GetComponent<Image>().sprite = sp;
TestChange(spp);
}
_heroProperty._textmp.text = _heroProperty.allMp.ToString();
break;
case 6:
if (_heroProperty.transform.GetChild(0).childCount>0)
{
_heroProperty.attack =
100 + _equipment
.equips[
int.Parse(_heroProperty.transform.GetChild(0).GetChild(0)
.GetComponent<Image>().sprite.name)].attack;
}
else
{
_heroProperty.attack =
100;
}
if (_heroProperty.transform.GetChild(6).childCount>0)
{
if (_heroProperty.transform.GetChild(0).childCount>0&&_heroProperty.transform.GetChild(6).childCount>0)
{
_heroProperty.attack =
100 + _equipment
.equips[
int.Parse(_heroProperty.transform.GetChild(0).GetChild(0)
.GetComponent<Image>().sprite.name)].attack+_equipment
.equips[
int.Parse(_heroProperty.transform.GetChild(6).GetChild(0)
.GetComponent<Image>().sprite.name)].attack;
}
else if (_heroProperty.transform.GetChild(6).childCount>0)
{
_heroProperty.attack =
100 + _equipment
.equips[
int.Parse(_heroProperty.transform.GetChild(6).GetChild(0)
.GetComponent<Image>().sprite.name)].attack;
}
else
{
_heroProperty.attack =
100;
}
if (_heroProperty.transform.GetChild(7).childCount>0)
{
Sprite spP = _heroProperty.transform.GetChild(7).GetChild(0).GetComponent<Image>()
.sprite;
if (sp.name==spP.name) return;
TestChange(spp);
_shopTest.btnOnClick(spP);
_heroProperty.transform.GetChild(7).GetChild(0).GetComponent<Image>().sprite = sp;
}
else
{
GameObject item6 = Instantiate(itemPre, _heroProperty.transform);
item6.transform.SetParent(_heroProperty.transform.GetChild(7));
item6.transform.localPosition=Vector3.zero;
item6.GetComponent<Image>().sprite = sp;
TestChange(spp);
}
}
else
{
GameObject item6 = Instantiate(itemPre, _heroProperty.transform);
item6.transform.SetParent(_heroProperty.transform.GetChild(6));
item6.transform.localPosition=Vector3.zero;
item6.GetComponent<Image>().sprite = sp;
TestChange(spp);
}
_heroProperty.attack += _equipment.equips[num].attack;
_heroProperty._textattack.text = _heroProperty.attack.ToString();
break;
}
});
}
}
}
}
private void TestChange(GameObject spp)
{
if (spp==null)
return;
if (spp.transform.GetChild(0).GetComponent<Text>().text==String.Empty||
int.Parse(spp.transform.GetChild(0).GetComponent<Text>().text)==1)
{
Destroy(spp);
}
else if (int.Parse(spp.transform.GetChild(0).GetComponent<Text>().text)>1)
{
spp.transform.GetChild(0).GetComponent<Text>().text =
(int.Parse(spp.transform.GetChild(0).GetComponent<Text>().text) - 1).ToString();
if (int.Parse(spp.transform.GetChild(0).GetComponent<Text>().text) ==1)
{
spp.transform.GetChild(0).GetComponent<Text>().text = string.Empty;
}
}
}
public EventSystem _mEventSystem;
public GraphicRaycaster gra;
private List<RaycastResult> GraphicRaycaster(Vector2 pos)
{
var mPointerEventData = new PointerEventData(_mEventSystem);
mPointerEventData.position = pos;
List<RaycastResult> results = new List<RaycastResult>();
gra.Raycast(mPointerEventData, results);
return results;
}
}
再一次返回场景 分两种 ,一个时开始进入一个时开始退出 ,一个变黑,一个变白 进行一系列的变化
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;
public class SceneAgain : MonoBehaviour
{
//屏幕淡入淡出的速度
public float fadeSpeed=5f;
//屏幕渐变的遮罩图片
private RawImage rawImage;
//屏幕是否正在消失
public bool sceneStarting=true;
private void Awake()
{
rawImage = GetComponent<RawImage>();
}
private void Update()
{
if (sceneStarting)
{
//开始淡入淡出
StartScene();
}
}
//遮罩图片变为透明
private void FadeClear()
{
rawImage.color=Color.Lerp(rawImage.color,Color.clear, fadeSpeed*Time.deltaTime);
}
//遮罩图片变得不透明
void FadeBlack()
{
rawImage.color=Color.Lerp(rawImage.color,Color.black, fadeSpeed*Time.deltaTime);
}
//开始渐变
public void StartScene()
{
FadeClear();
//如果屏幕颜色接近透明
if (rawImage.color.a<=0.05f)
{
//将图片设置透明,并且设置不激活
rawImage.color=Color.clear;
rawImage.enabled = false;
sceneStarting = false;
}
}
//游戏结束
public void EndScene()
{
//开启渐变模式
rawImage.enabled = true;
//开始变黑
FadeBlack();
if (rawImage.color.a>=0.95f)
{
//重新开始 重新加载当前的场景
SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex);
}
}
}
进入场景的时候用到了协程,异步加载速度是很快的, 先申明异步加载的场景,不想允许跳转,异步加载的进度最高为0.9,所以当他为0.9的时候设为1,把他的进度给滑动条,文字显示也是这样,当他大于0.9时然后让他按任意按键就允许跳转,然后退出协程
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;
using AsyncOperation = System.ComponentModel.AsyncOperation;
public class SceneAllManage : MonoBehaviour
{
public void SceneToPlaying()
{
StartCoroutine(WaitToStart());
}
//异步加载
IEnumerator WaitToStart()
{
UnityEngine.AsyncOperation asyncOperation = SceneManager.LoadSceneAsync("Playing");
asyncOperation.allowSceneActivation = false;
//当没有结束的时候
while (!asyncOperation.isDone)
{
//加载进度小于0.69,直接让他滑动条为1
if (asyncOperation.progress < 0.9f)
GameObject.Find("Wait5").transform.GetChild(4).GetComponent<Scrollbar>().size = asyncOperation.progress;
else
GameObject.Find("Wait5").transform.GetChild(4).GetComponent<Scrollbar>().size = 1.0f;
//文字
GameObject.Find("Wait5").transform.GetChild(5).GetComponent<Text>().text =
GameObject.Find("Wait5").transform.GetChild(4).GetComponent<Scrollbar>().size.ToString("P1");
//当比0.9大的时候
if (asyncOperation.progress >= 0.9f)
{
//切换文字样式
GameObject.Find("Wait5").transform.GetChild(5).GetComponent<Text>().text = "输入任意键进入...";
if (Input.anyKeyDown)
{
asyncOperation.allowSceneActivation = true;
}
}
//离开携程
yield return null;
}
}
public void Quit()
{
Application.Quit();
}
}
商店的话开局先加载图片到商店里面,然后用背包的哪个方法进行遍历和加减数值
using System;
using UnityEngine;
using UnityEngine.UI;
public class ShopTest : MonoBehaviour
{
//商店按钮预设体
public GameObject btnPre;
//背包图片预设体
public GameObject itemPre;
//商店父物体
public Transform shopTf;
//背包父物体
public Transform packageTf;
private void Start()
{
for (int i = 0; i < 29; i++)
{
//加载精灵图片
Sprite sp = Resources.Load<Sprite>(i.ToString());
//加载按钮
GameObject btn = Instantiate(btnPre, shopTf);
//将精灵图片放在按钮上
btn.GetComponent<Image>().sprite = sp;
//添加点击事件
// btn.GetComponent<Button>().onClick.AddListener(() =>
// {
// btnOnClick(sp);
// });
}
}
/// <summary>
/// 点击事件
/// </summary>
/// <param name="sp"></param>
public void btnOnClick(Sprite sp)
{
//遍历背包格子
for (int i = 0; i < packageTf.childCount; i++)
{
Transform cell = packageTf.GetChild(i);
//如果格子有子物体
if (cell.childCount>0)
{
//如果格子上的子物体上的图片与要添加的图片一样
if (cell.GetChild(0).GetComponent<Image>().sprite.name==sp.name)
{
//获取图片上的文本
Text numberText = cell.GetChild(0).GetComponentInChildren<Text>();
//如果文本为空
if (numberText.text==String.Empty)
{
//将文本设为”1“
numberText.text = "1";
}
//转化为int类型
int count = int.Parse(numberText.text);
count++;
//转化为string类型
numberText.text = count.ToString();
return;
}
}
}
//如果代码能到达此地,说明所选物品没有购买过,在空格子处生成新物品
for (int i = 0; i < packageTf.childCount; i++)
{
Transform cell = packageTf.GetChild(i);
//当没有子物体的时候
if (cell.childCount==0)
{
//生成一个图片
GameObject item = Instantiate(itemPre, cell.transform);
item.transform.localPosition = Vector2.zero;
//给与图片加上精灵图片
item.GetComponent<Image>().sprite = sp;
//打开number
item.transform.GetChild(0).gameObject.SetActive(true);
return;
}
}
}
}
显示名字的话直接跟随和看向摄像机
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class ShowName : MonoBehaviour
{
public Transform model; //主角对象
public float height;
// Update is called once per frame
void Update ()
{
if (model==null)
{
return;
}
transform.LookAt(Camera.main.transform.position);
transform.position = new Vector3(model.position.x,model.position.y+height,model.position.z);
}
}
技能树就是激活和不激活的问题,当激活的时候cd开始显示变亮,关闭按钮不能再次激活,还有个显示面板技能信息,当点击升级的那个按钮的时候打开图片亮度,并且减去需要的技能点数
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Serialization;
using UnityEngine.UI;
public class SkillTree : MonoBehaviour
{
private Text _allNum;
private Text _skillName;
private Text _skillNeedNum;
private Text _skillMassage;
private Text _skillMpText;
private GameObject _panel;
public GameObject pass2;
public GameObject pass3;
public GameObject pass4;
public bool up2;
public bool up3;
public bool up4;
private Button _btn1;
public Button btn2;
public Button btn3;
public Button btn4;
private Button _btnUp2;
private Button _btnUp3;
private Button _btnUp4;
private CdShow _cdShow;
private HeroProperty _heroProperty;
private void Start()
{
_cdShow = GameObject.Find("CanvasScene").transform.GetChild(0).GetChild(0).GetComponent<CdShow>();
_heroProperty = GameObject.FindWithTag("Property").GetComponent<HeroProperty>();
_panel = transform.GetChild(5).gameObject;
pass2 = transform.GetChild(2).GetChild(0).gameObject;
pass3 = transform.GetChild(3).GetChild(0).gameObject;
pass4 = transform.GetChild(4).GetChild(0).gameObject;
_panel.SetActive(false);
// pass2.SetActive(false);
// pass3.SetActive(false);
// pass4.SetActive(false);
_allNum = transform.GetChild(0).GetChild(0).GetComponent<Text>();
_allNum.text=_heroProperty.allNum.ToString();
_skillName = transform.GetChild(5).GetChild(0).GetComponent<Text>();
_skillNeedNum = transform.GetChild(5).GetChild(1).GetComponent<Text>();
_skillMassage = transform.GetChild(5).GetChild(2).GetComponent<Text>();
_skillMpText= transform.GetChild(5).GetChild(3).GetComponent<Text>();
_btn1 = transform.GetChild(1).GetChild(0).GetComponent<Button>();
btn2 = transform.GetChild(2).GetChild(1).GetComponent<Button>();
btn3 = transform.GetChild(3).GetChild(1).GetComponent<Button>();
btn4 = transform.GetChild(4).GetChild(1).GetComponent<Button>();
_btnUp2=transform.GetChild(2).GetChild(2).GetComponent<Button>();
_btnUp3=transform.GetChild(3).GetChild(2).GetComponent<Button>();
_btnUp4=transform.GetChild(4).GetChild(2).GetComponent<Button>();
_btn1.onClick.AddListener(() =>
{
BtnOnClick1();
});
btn2.onClick.AddListener(() =>
{
BtnOnClick2();
});
btn3.onClick.AddListener(() =>
{
BtnOnClick3();
});
btn4.onClick.AddListener(() =>
{
BtnOnClick4();
});
_btnUp2.onClick.AddListener(() =>
{
BtnUpOnClick2();
});
_btnUp3.onClick.AddListener(() =>
{
BtnUpOnClick3();
});
_btnUp4.onClick.AddListener(() =>
{
BtnUpOnClick4();
});
}
private void Update()
{
_allNum.text = _heroProperty.allNum.ToString();
if (up2)
{
_btnUp2.enabled = false;
}
if (up3)
{
_btnUp3.enabled = false;
}
if (up4)
{
_btnUp4.enabled = false;
}
}
public void BtnOnClick1()
{
_panel.SetActive(true);
_skillName.text = "技能1";
_skillNeedNum.text = "0";
_skillMassage.text = "强";
_skillMpText.text = _cdShow.needMp1.ToString();
}
public void BtnOnClick2()
{
_panel.SetActive(true);
_skillName.text = "技能2";
_skillNeedNum.text = "2";
_skillMassage.text = "很强";
_skillMpText.text = _cdShow.needMp2.ToString();
}
public void BtnOnClick3()
{
_panel.SetActive(true);
_skillName.text = "技能3";
_skillNeedNum.text = "4";
_skillMassage.text = "特别强";
_skillMpText.text = _cdShow.needMp3.ToString();
}
public void BtnOnClick4()
{
_panel.SetActive(true);
_skillName.text = "技能4";
_skillNeedNum.text = "8";
_skillMassage.text = "碉堡的强";
_skillMpText.text = _cdShow.needMp4.ToString();
}
public void BtnUpOnClick2()
{
if (_heroProperty.allNum>2)
{
up2 = true;
pass2.SetActive(true);
_heroProperty.allNum=_heroProperty.allNum-2;
btn2.GetComponent<Image>().color=Color.white;
}
}
public void BtnUpOnClick3()
{
if (_heroProperty.allNum>4)
{
up3 = true;
pass3.SetActive(true);
_heroProperty.allNum=_heroProperty.allNum-4;
btn3.GetComponent<Image>().color=Color.white;
}
}
public void BtnUpOnClick4()
{
if (_heroProperty.allNum>8&&up2&&up3)
{
up4 = true;
pass4.SetActive(true);
_heroProperty.allNum=_heroProperty.allNum-8;
btn4.GetComponent<Image>().color=Color.white;
}
}
}
using UnityEngine;
using UnityEngine.UI;
public class UIOption : MonoBehaviour
{
//音乐声音大小
public Scrollbar musicScrollbar;
//音量toggle
public Toggle musicToggle;
//音效toggle
public Toggle audioToggle;
//音效声音大小
public Scrollbar audioScrollbar;
private void Awake()
{
//注册点击事件
musicToggle.onValueChanged.AddListener(MusicToggleOnChange);
audioToggle.onValueChanged.AddListener(AudioToggleOnChange);
//根据播放器更改按钮状态
musicToggle.isOn = !SoundManage.Instance.MusicMute;
audioToggle.isOn = !SoundManage.Instance.AudioMute;
}
private void Start()
{
//给滑动条的值赋给音乐音量
musicScrollbar.value = SoundManage.Instance.Volume;
audioScrollbar.value = SoundManage.Instance.AudioVolume;
//播放bgm6
SoundManage.Instance.PlayBgm("天涯明月刀"); ;
}
private void Update()
{
//调节滑动条的值控制声音音量大小
SoundManage.Instance.Volume = musicScrollbar.value;
//调节滑动条的值控制音效音量大小
SoundManage.Instance.AudioVolume = audioScrollbar.value;
if (Input.GetMouseButtonDown(0))
{
SoundManage.Instance.PlayAudio("Button - Click",new Vector2(0,0),
SoundManage.Instance.AudioVolume);
}
}
/// <summary>
/// 设置界面返回按钮的点击事件
/// </summary>
public void GoBack()
{
//播放音效
}
/// <summary>
/// 音乐开关
/// </summary>
/// <param name="value"></param>
private void MusicToggleOnChange(bool value)
{
//播放音效
SoundManage.Instance.PlayAudio("天涯明月刀",transform.position,SoundManage.Instance.AudioVolume);
SoundManage.Instance.MusicMute = !value;
}
/// <summary>
/// 音效开关
/// </summary>
/// <param name="value"></param>
private void AudioToggleOnChange(bool value)
{
//播放音效
SoundManage.Instance.PlayAudio("Button - Click",transform.position,SoundManage.Instance.AudioVolume);
SoundManage.Instance.AudioMute = !value;
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;
public class UISet : MonoBehaviour
{
//所有音乐文件的名字
public string[] AllMusicName;
//显示音乐名字
private Text _musicText;
//播放到的第几个音乐
private int _musicId;
//音量toggle
private Toggle _musicToggle;
//音乐声音大小
private Scrollbar _musicScrollbar;
//音量toggle
private Toggle _audioToggle;
//音乐声音大小
private Scrollbar _audioScrollbar;
private float a;
private void Start()
{
//获取音乐文本组件
_musicText = transform.GetChild(0).GetChild(6).GetComponent<Text>();
//获取控制音乐音量的滑动条
_musicScrollbar = transform.GetChild(0).GetChild(4).GetChild(2).GetComponent<Scrollbar>();
//获取控制音效音量的滑动条
_audioScrollbar = transform.GetChild(0).GetChild(5).GetChild(2).GetComponent<Scrollbar>();
//获取音效按钮
_audioToggle = transform.GetChild(0).GetChild(5).GetChild(1).GetComponent<Toggle>();
//获取音乐按钮
_musicToggle = transform.GetChild(0).GetChild(4).GetChild(1).GetComponent<Toggle>();
//注册点击事件
_musicToggle.onValueChanged.AddListener(MusicToggleOnChange);
_audioToggle.onValueChanged.AddListener(AudioToggleOnChange);
//根据播放器更改按钮状态
_musicToggle.isOn = !SoundManage.Instance.MusicMute;
_audioToggle.isOn = !SoundManage.Instance.AudioMute;
//给滑动条的值赋给音乐音量
_musicScrollbar.value = SoundManage.Instance.Volume;
_audioScrollbar.value = SoundManage.Instance.AudioVolume;
//存储音乐
AllMusicName = new[] {"揽仙镇","天涯明月刀", "森林狂想曲"};
//播放bgm
SoundManage.Instance.PlayBgm(AllMusicName[_musicId]);
//显示音乐名字
_musicText.text = SoundManage.Instance.musicShowName;
//按钮点击事件
}
private void Update()
{
//调节滑动条的值控制声音音量大小
SoundManage.Instance.Volume = _musicScrollbar.value;
SoundManage.Instance.AudioVolume = _audioScrollbar.value;
if (Input.GetMouseButtonDown(0))
{
SoundManage.Instance.PlayAudio("Button - Click",new Vector2(0,0),
SoundManage.Instance.AudioVolume);
}
}
/// <summary>
/// 下一首
/// </summary>
public void PlayerNextMusic()
{
_musicId++;
if (_musicId>AllMusicName.Length-1)
{
_musicId = 0;
}
//播放音乐
SoundManage.Instance.PlayBgm(AllMusicName[_musicId]);
//显示名字
_musicText.text = AllMusicName[_musicId];
}
/// <summary>
/// 上一首
/// </summary>
public void PlayerLastMusic()
{
_musicId--;
if (_musicId<0)
{
_musicId = AllMusicName.Length-1;
}
//播放音乐
SoundManage.Instance.PlayBgm(AllMusicName[_musicId]);
//显示名字
_musicText.text = AllMusicName[_musicId];
}
/// <summary>
/// 音乐开关
/// </summary>
/// <param name="value"></param>
private void MusicToggleOnChange(bool value)
{
SoundManage.Instance.MusicMute = !value;
}
private void AudioToggleOnChange(bool value)
{
SoundManage.Instance.AudioMute = !value;
}
public void ToStartScene()
{
SceneManager.LoadScene(1);
}
// public void TimeTo0()
// {
// Time.timeScale = 0;
// }
public void TimeTo1()
{
Time.timeScale = 1;
}
public void SaveMsg()
{
//保留当前的设置
PlayerPrefs.SetInt(SoundManage.MUSICMUTE,SoundManage.Instance.MusicMute?1:0);
PlayerPrefs.SetInt(SoundManage.AUDIOMUTE,SoundManage.Instance.AudioMute?1:0);
PlayerPrefs.SetFloat(SoundManage.VOLUME,SoundManage.Instance.Volume);
PlayerPrefs.SetFloat(SoundManage.AUDIOVOLUME,SoundManage.Instance.AudioVolume);
}
}