using UnityEngine; public class MonsterShootToPlayer2D : MonoBehaviour { public GameObject player; public GameObject bullet; public float speed = 50f; public float bulletTime = 5.0f; public float firePause = 3.0f; Vector3 targetPos; float angle; void Start() { InvokeRepeating("F1", 1.0f, firePause); } void F1() { GameObject tmp = Instantiate(bullet, transform.position, Quaternion.Euler(0, 0, 0)); targetPos = player.transform.position; targetPos.x = targetPos.x - transform.position.x; targetPos.y = targetPos.y - transform.position.y; angle = Mathf.Atan2(targetPos.y, targetPos.x) * Mathf.Rad2Deg; tmp.transform.rotation = Quaternion.Euler(new Vector3(0, 0, angle - 90)); tmp.GetComponent().AddForce(tmp.transform.up * speed); tmp.transform.Rotate(new Vector3(0, 0, 90f)); Destroy(tmp, bulletTime); } }