夏天的风

将来的你一定会感激现在努力的自己

《组合变身小宠物游戏》Fighting战斗UI(修改更新中)【初学者】

using UnityEngine;
using System.Collections;
using UnityEngine.UI;
using UnityEngine.Sprites;
using System.Collections.Generic;
public class Fighting : MonoBehaviour {
    public Text TextPlayerBlood;
    public Text TextMonsterBlood;
    public Text TextPlayerAttack;
    public Text TextMonsterAttack;
    public Image PlayerPetImage;
    public Image MonsterPetImage;
    public GameObject parentObj_player;
    public GameObject parentObj_monster;
    public GameObject[] gridItemObj_player = new GameObject[3];
    public GameObject[] gridItemObj_monster = new GameObject[2];
    public static Fighting self;
    public List<PlayerPetItem> PlayerPetItemList = new List<PlayerPetItem>();
    public List<MonsterPetItem> MonsterPetItemList = new List<MonsterPetItem>();//#001#
    public PetXmlData CatchPetData;//记录被捕捉的怪物(胜利时捕捉)
    


    void OnEnable()
    {
        PlayerPetItemList.Clear();
        MonsterPetItemList.Clear();
        InitPlayerPetItem();
        InitMonsterPetItem();
       // CatchPetData = gridItemObj_monster[1].GetComponent<MonsterPetItem>().MonsterPetXmlVO;//这里导致捕捉宠物血量为战斗后的0
        
    }


    void Awake()
    {
        self = this;
    }
    void Start()
    {


    }
  public void InitPlayerPetItem()//人物宠物显示固定加载3个
  {
      UnityEngine.Object gridItem = Resources.Load("Prefabs/item/" + "PlayerPetItem");
      for (int i = 0; i < gridItemObj_player.Length; i++)//
      {
          gridItemObj_player[i] = GameObject.Instantiate(gridItem) as GameObject;
          gridItemObj_player[i].name = "PlayerPetItem" + (i + 1).ToString();//添加的预制体的名字
          gridItemObj_player[i].transform.parent = parentObj_player.transform;
          gridItemObj_player[i].transform.localPosition = Vector3.zero;
          gridItemObj_player[i].transform.localScale = Vector3.one;
          PlayerPetItemList.Add(gridItemObj_player[i].GetComponent<PlayerPetItem>());
          gridItemObj_player[i].GetComponent<PlayerPetItem>().index = i + 1;
      }


  }
  public void InitMonsterPetItem() //怪物宠物显示固定加载2个
  {
      UnityEngine.Object gridItem = Resources.Load("Prefabs/item/" + "MonsterPetItem");
      for (int i = 0; i < gridItemObj_monster.Length; i++)
      {
          gridItemObj_monster[i] = GameObject.Instantiate(gridItem) as GameObject;
          gridItemObj_monster[i].name = "MonsterPetItem" + (i + 1).ToString();//添加的预制体的名字
          gridItemObj_monster[i].transform.parent = parentObj_monster.transform;
          gridItemObj_monster[i].transform.localPosition = Vector3.zero;
          gridItemObj_monster[i].transform.localScale = Vector3.one;
          MonsterPetItemList.Add(gridItemObj_monster[i].GetComponent<MonsterPetItem>());
          gridItemObj_monster[i].GetComponent<MonsterPetItem>().index = i + 1;
         // CatchPetData = gridItemObj_monster[i].GetComponent<MonsterPetItem>().MonsterPetXmlVO;//一轮加载后,取的是最后一个作为被抓怪物
      }
      
  }




    
    public void escape()//逃跑
    {
        UIManager.instance.HidePanel(UIPanelNames.FightingPanel);//隐藏战斗UI
        DestoryItem();//销毁加载的预制体
        RoleControl.self.IsInFight= false;//战斗状态切换
       // RunPanel.self.TeamShowitem();//更新RunPanel队伍显示


        if (GameMonster.self.gameCount == 10)//游戏完成
        {
            UIManager.instance.ShowPanel(UIPanelNames.ComPletePanel);
        }
       
    }


    public void OnClose()//关闭
    {
        UIManager.instance.HidePanel(UIPanelNames.FightingPanel);//隐藏战斗UI
        DestoryItem();//销毁加载的预制体
        RoleControl.self.IsInFight = false;//战斗状态切换
        //RunPanel.self.TeamShowitem();//更新RunPanel队伍显示
        
    }


    public void DestoryItem()//(退出战斗界面时需要)清除加载的宠物和怪物预制体
    {
        for (int i = 0; i < parentObj_player.transform.childCount; i++)
        {
            GameObject go = parentObj_player.transform.GetChild(i).gameObject;
            Destroy(go);
        }
        for (int i = 0; i < parentObj_monster.transform.childCount; i++)
        {
            GameObject go = parentObj_monster.transform.GetChild(i).gameObject;
            Destroy(go);
        }
    }

}














阅读更多
版权声明:本文为博主“等木鱼的猫”原创文章,转载请注明出处 http://blog.csdn.net/u012761191 https://blog.csdn.net/u012761191/article/details/52353642
个人分类: unity
上一篇《组合变身小宠物游戏》ConfigManager(修改更新中)【初学者】
下一篇《组合变身小宠物游戏》PetCombine宠物组合(修改更新中)【初学者】
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

关闭
关闭