15556人加入学习
(100人评价)
通过实例学习:游戏的存档与读档(Unity 2017.2)

制作完成于2018-1-12

价格 免费

public GameObject[ ] monster;

public GameObject activateMonster=null;

private void ActivateMonster(){

int index = Random.Range(0,monsters.Length);

activateMonster=monsters[index];

activateMonster.SetActive(true);

activateMonster.GetComponent<BoxCollider>().enabled=true;

}

 

[展开全文]

using System.Collections; using System.Collections.Generic; using UnityEngine; public class TargetManager : MonoBehaviour { public GameObject[] monsters; public GameObject activeMonster = null; private void Start() { foreach(GameObject monster in monsters) { monster.GetComponent().enabled = false; monster.SetActive(false); } ActivateMonster(); } private void ActivateMonster() { int index = Random.Range(0,monsters.Length); activeMonster = monsters[index]; activeMonster.SetActive(true); activeMonster.GetComponent().enabled = true; } }

[展开全文]

//随机生成怪物,用索引生成

public GameObject[] monstrers;
    public GameObject activeMonster = null;
    void Start()
    {
        foreach ( GameObject   monstrer in monstrers)
        {
            monstrer.SetActive(false);
            monstrer.GetComponent<BoxCollider>().enabled = false;
           
       
        }
        ActivateMonster();
    }
    private void ActivateMonster()
    {
        int index = Random.Range(0, monstrers.Length);
        activeMonster = monstrers[index];
        activeMonster.SetActive(true);
        activeMonster.GetComponent<BoxCollider>().enabled = true;
    }
  
    // Update is called once per frame
[展开全文]

前8个课程都是搭建场景的,未写代码

[展开全文]

給Target添加一個腳本

把void start和voidUpdate刪掉

public GameObject[]mosters;

public GameObject activateMonster = null;

把四種怪物都拖進腳本

ptivate void Start(){

foreach(GameObject monster in monsters)

{

monster.SetActivate(false);

monster.GetComponent<BoxCollider>.enabled = false;

}

ActivateMonster();

}

private void ActivateMonster()

{

int index = Range(0,monsters.Lenght);

activateMonster = monster[index];

activate.SetActive(true);

activate.GetCompoment<BoxCollider>().enabled = true;

}

[展开全文]
  • 游戏物体激活:

游戏物体.SetActive(true);

  • 游戏物体组件激活:

游戏物体.GetComponent<组件>().enabled=true;

[展开全文]

授课教师

SIKI学院老师

课程特色

图文(1)
下载资料(1)
视频(34)

学员动态