30 lines
753 B
C#
30 lines
753 B
C#
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
public class AutoAim : MonoBehaviour
|
|
{
|
|
// Start is called before the first frame update
|
|
public GameObject enemy;
|
|
|
|
public float lookSpeed = 200f;
|
|
|
|
public GameObject player;
|
|
public Camera camera;
|
|
void Start()
|
|
{
|
|
|
|
}
|
|
|
|
// Update is called once per frame
|
|
void Update()
|
|
{
|
|
Vector3 direction = enemy.transform.position - camera.transform.position;
|
|
Quaternion targetRotation = Quaternion.LookRotation(direction);
|
|
Quaternion lookAt = Quaternion.RotateTowards(camera.transform.rotation, targetRotation, Time.deltaTime * lookSpeed);
|
|
camera.transform.rotation = lookAt;
|
|
|
|
}
|
|
}
|