最近在做仿真的时候用到了Unity搭环境,要写一些简单的Unity脚本
在对照ml-agent的官方文档学习时候发现这样一段代码
using System.Collections.Generic;
using UnityEngine;
using Unity.MLAgents;
using Unity.MLAgents.Sensors;
public class RollerAgent : Agent
{
Rigidbody rBody;
void Start () {
rBody = GetComponent<Rigidbody>();
}
public Transform Target;
public override void OnEpisodeBegin()
{
// If the Agent fell, zero its momentum
if (this.transform.localPosition.y < 0)
{
this.rBody.angularVelocity = Vector3.zero;
this.rBody.velocity = Vector3.zero;
this.transform.localPosition = new Vector3( 0, 0.5f, 0);
}
// Move the target to a new spot
Target.localPosition = new Vector3(Random.value * 8 - 4,
0.5f,
Random.value * 8 - 4);
}
}
发现这个Target变量似乎没有进行赋值???后面直接调用了
然后找了一老顿,发现似乎public变量可以直接在 Inspector 面板中直接设置。在脚本组件里就会出现target这个框框,把对象拖进去就可以了。
下一步就是把unity和python的通讯调好,祝我好运。