Unity 机器学习代理工具包 (ML-Agents) 是一个开源项目,它使游戏和模拟能够作为训练智能代理的环境。
您最多选择25个主题 主题必须以中文或者字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
 
 
 
 
 

58 行
1.7 KiB

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using MLAgents;
public class BananaArea : Area
{
public GameObject banana;
public GameObject badBanana;
public int numBananas;
public int numBadBananas;
public bool respawnBananas;
public float range;
// Use this for initialization
void Start()
{
}
// Update is called once per frame
void Update()
{
}
void CreateBanana(int numBana, GameObject bananaType)
{
for (int i = 0; i < numBana; i++)
{
GameObject bana = Instantiate(bananaType, new Vector3(Random.Range(-range, range), 1f,
Random.Range(-range, range)) + transform.position,
Quaternion.Euler(new Vector3(0f, Random.Range(0f, 360f), 90f)));
bana.GetComponent<BananaLogic>().respawn = respawnBananas;
bana.GetComponent<BananaLogic>().myArea = this;
}
}
public void ResetBananaArea(GameObject[] agents)
{
foreach (GameObject agent in agents)
{
if (agent.transform.parent == gameObject.transform)
{
agent.transform.position = new Vector3(Random.Range(-range, range), 2f,
Random.Range(-range, range))
+ transform.position;
agent.transform.rotation = Quaternion.Euler(new Vector3(0f, Random.Range(0, 360)));
}
}
CreateBanana(numBananas, banana);
CreateBanana(numBadBananas, badBanana);
}
public override void ResetArea()
{
}
}