【发布时间】:2016-04-30 22:06:15
【问题描述】:
我试图在玩家进入敌人的半径区域时让敌人跟随我的玩家,但是当我的子弹击中object 或进入radiusArea 时让敌人停止跟随。
查看我的 gif 以获得更多详细信息:
脚本:
using UnityEngine;
using System.Collections;
public class FlyEnemyMove : MonoBehaviour
{
public float moveSpeed;
public float playerRange;
public LayerMask playerLayer;
public bool playerInRange;
PlayerController thePlayer;
// Use this for initialization
void Start()
{
thePlayer = FindObjectOfType<PlayerController>();
}
// Update is called once per frame
void Update()
{
flip();
playerInRange = Physics2D.OverlapCircle(transform.position, playerRange, playerLayer);
if (playerInRange)
{
transform.position = Vector3.MoveTowards(transform.position, thePlayer.transform.position, moveSpeed * Time.deltaTime);
//Debug.Log(transform.position.y);
}
//Debug.Log(playerInRange);
}
void OnDrawGizmosSelected()
{
Gizmos.DrawWireSphere(transform.position, playerRange);
}
void flip()
{
if (thePlayer.transform.position.x < transform.position.x)
{
transform.localScale = new Vector3(0.2377247f, 0.2377247f, 0.2377247f);
}
else
{
transform.localScale = new Vector3(-0.2377247f, 0.2377247f, 0.2377247f);
}
}
}
希望有人能帮帮我:(
【问题讨论】:
-
你的 gif 不工作,伤心!
-
就像乔说的那样,您的图片链接不起作用。我修好了它。请务必测试您的图片链接时间。
标签: c# unity3d unityscript unity5