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

85 行
2.0 KiB

using UnityEngine;
//This script handles the logic to determine whether an active projectile
//...should be remain active after it has been shot by an enemy
public class Projectile : MonoBehaviour
{
public float aliveTime;
[HideInInspector] public Rigidbody rb;
// private ObstacleTowerAgent agent;
public bool selfDestructNow;
public float maxTimeToLive = 3;
public float pauseCollisionDetectionWaitTime = .5f;
// [HideInInspector] public ShootProjectiles projectileController;
void Awake()
{
rb = GetComponent<Rigidbody>();
// agent = FindObjectOfType<ObstacleTowerAgent>();
}
void OnEnable()
{
if (!rb)
{
rb = GetComponent<Rigidbody>();
}
aliveTime = 0;
selfDestructNow = false;
// if (agent)
// {
// agent.CompletedFloorAction += SelfDestruct;
// }
}
void OnDisable()
{
aliveTime = 0;
// if (agent)
// {
// agent.CompletedFloorAction -= SelfDestruct;
// }
}
//Turn the projectile off
void SelfDestruct()
{
gameObject.SetActive(false);
// rb.velocity = Vector3.zero;
// rb.angularVelocity = Vector3.zero;
}
void FixedUpdate()
{
// if (
// (agent && agent.IsDone()) //if the agent is done projectiles can die
// || aliveTime > maxTimeToLive //we lived too long. time to die
// )
if (aliveTime > maxTimeToLive) //we lived too long. time to die
{
selfDestructNow = true;
}
if (selfDestructNow)
{
SelfDestruct();
}
aliveTime += Time.fixedDeltaTime;
}
void OnCollisionEnter(Collision col)
{
if (aliveTime > pauseCollisionDetectionWaitTime)
{
selfDestructNow = true;
}
// print(col.gameObject.name);
}
}