Unity3d 如何在没有公共游戏对象的情况下禁用另一个游戏中的脚本?
我只想禁用我的播放器管理器中的脚本。但是因为我的敌人是通过Unity3d 如何在没有公共游戏对象的情况下禁用另一个游戏中的脚本?,unity3d,Unity3d,我只想禁用我的播放器管理器中的脚本。但是因为我的敌人是通过设置为活动的产生的,所以公共游戏对象就是不起作用。我试着让我的球员教练也成为一个预制场,但没有解决办法。我可以通过脚本中的特定游戏对象通过代码行手动指定它吗 虽然这看起来很小,但我确实做过研究,而且大部分都指向专门使用publicgameobject。除非我对C#还不够了解 public float lookRadius=40f; //公众投票站; 转化目标; UnityEngine.AI.NavMesh代理; 刚体; void Star
设置为活动的产生的,所以公共游戏对象就是不起作用。我试着让我的球员教练也成为一个预制场,但没有解决办法。我可以通过脚本中的特定游戏对象通过代码行手动指定它吗
虽然这看起来很小,但我确实做过研究,而且大部分都指向专门使用publicgameobject
。除非我对C#还不够了解
public float lookRadius=40f;
//公众投票站;
转化目标;
UnityEngine.AI.NavMesh代理;
刚体;
void Start(){
target=PlayerManager.instance.player.transform;
agent=GetComponent();
}
无效更新(){
浮动距离=矢量3.距离(target.position,transform.position);
如果(距离您可以执行类似于FindObjectOfType().enabled=false的操作
public float lookRadius = 40f;
//public Casting stop;
Transform target;
UnityEngine.AI.NavMeshAgent agent;
Rigidbody theRigidBody;
void Start(){
target = PlayerManager.instance.player.transform;
agent = GetComponent<UnityEngine.AI.NavMeshAgent>();
}
void Update(){
float distance = Vector3.Distance (target.position, transform.position);
if (distance <= lookRadius)
{
agent.SetDestination (target.position);
if (distance <= agent.stoppingDistance)
{
FaceTarget ();
}
if (distance < 10f) // or some distance
{
//gameObject.GetComponent<Casting>().enabled = false;
Debug.Log("nearby heyy");
}
}
}
void FaceTarget()
{
Vector3 direction = (target.position - transform.position).normalized;
Quaternion lookRotation = Quaternion.LookRotation (new Vector3 (direction.x, 0, direction.z));
transform.rotation = Quaternion.Slerp (transform.rotation, lookRotation, Time.deltaTime * 5f);
}
// Use this for initialization
public void OnObjectSpawn () {
//myRender = GetComponent<Renderer> ();
theRigidBody = GetComponent<Rigidbody>();
}
void OnDrawGizmosSelected()
{
Gizmos.color = Color.red;
Gizmos.DrawWireSphere (transform.position, lookRadius);
}