-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEnemyAI.cs
More file actions
46 lines (44 loc) · 1.5 KB
/
EnemyAI.cs
File metadata and controls
46 lines (44 loc) · 1.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class EnemyAI : MonoBehaviour {
public float fpstargetdistance; //hedefe ne kadar uzak
public float enemylookdistance; //ne kadar uzaktan görecek
public float attackdistance; //ne kadar menzili var
public float enemymovementspeed;
public float damping;
public Transform fpstarget;
Rigidbody rb;
//Renderer rend;
// Use this for initialization
void Start () {
//rend = GetComponent<Renderer>();
rb = GetComponent<Rigidbody>();
}
// Update is called once per frame
void FixedUpdate () {
fpstargetdistance = Vector3.Distance(fpstarget.position,transform.position); //bu distance bulma fonksiyonu bunu unutma.
if (fpstargetdistance < enemylookdistance )
{
//rend.material.color = Color.yellow;
lookAtPlayer();
//print("Look at the player please");
}
if (fpstargetdistance < attackdistance)
{
attackPlease();
//Debug.Log("Attack");
}
}
public void lookAtPlayer()
{
Quaternion rotation = Quaternion.LookRotation(fpstarget.position - transform.position);
transform.rotation = Quaternion.Slerp(transform.rotation,rotation,Time.deltaTime * damping);
}
public void attackPlease()
{
//Debug.Log("Moving");
rb.AddForce(transform.forward * enemymovementspeed);
//rb.velocity = (transform.forward * enemymovementspeed);
}
}