【发布时间】:2021-07-12 20:09:59
【问题描述】:
到目前为止,敌人可以跟随玩家并可以将枪对准玩家。我现在唯一需要做的就是让敌人向玩家射击。
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Enemy : MonoBehaviour
{
public GameObject player;
public GameObject gun;
void Update()
{
Vector3 difference = player.transform.position - gun.transform.position;
float rotationZ = Mathf.Atan2(difference.y, difference.x) * Mathf.Rad2Deg;
gun.transform.rotation = Quaternion.Euler(0.0f, 0.0f, rotationZ);
}
}
【问题讨论】: