私は、プレーヤーが敵の半径エリアに入ったときに自分のプレイヤーに追いつこうとしていますが、弾丸がobject
に達するか、radiusArea
と入力されたときに敵を止めさせます。ユニティ3D、敵追従号
詳細については、私の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が動作していない、悲しい! – Fattie
ちょうどジョーが言ったように、画像のリンクが機能していません。それを私が直した。画像のリンク時間を確認してください。 – Programmer