我对这个话题研究了很多,但始终找不到正确的解决方案。我有一个红钻石形状的敌人,我希望得分总是面对球员。我已经成功地让他们向玩家移动,但还没有让他们面对。下面是我的敌人移动代码和敌人的图像。
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class EnemyMovement : MonoBehaviour
{
[SerializeField] private float _speed = 9;
private Transform _target;
void Awake()
{
_target = GameObject.FindGameObjectWithTag("Player").transform;
}
void Update()
{
transform.position = Vector3.MoveTowards(transform.position, _target.position, _speed * Time.deltaTime);
}
}
这是我的敌人精灵的照片链接
您好!
尝试调查:https://docs.unity3d.com/ScriptReference/Transform.LookAt.html这可能是最简单、最好的解决方案,但也有其他方法,如:https://docs.unity3d.com/ScriptReference/Quaternion.SetLookRotation.html你可以用它来设置敌人总是看着玩家。
我可能会使用LookAt
我希望这对你的编码有帮助,祝你好运