...
This commit is contained in:
32
Assets/Scripts/Character/AutoAim.cs
Normal file
32
Assets/Scripts/Character/AutoAim.cs
Normal file
@ -0,0 +1,32 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class AutoAim : MonoBehaviour
|
||||
{
|
||||
|
||||
public GameObject enemy;
|
||||
|
||||
public float lookSpeed = 200;
|
||||
|
||||
public GameObject head;
|
||||
public Camera cam;
|
||||
|
||||
void Start()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
if (enemy)
|
||||
{
|
||||
Vector3 direction = enemy.transform.position - cam.transform.position;
|
||||
Quaternion targetRotation = Quaternion.LookRotation(direction);
|
||||
Quaternion lookAt = Quaternion.RotateTowards(cam.transform.rotation, targetRotation, Time.deltaTime * lookSpeed);
|
||||
cam.transform.rotation = lookAt;
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user