Advertisement
Guest User

Untitled

a guest
Feb 26th, 2017
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.50 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class EnemyAI : MonoBehaviour {
  6. public float fpstargetdistance; //hedefe ne kadar uzak
  7. public float enemylookdistance; //ne kadar uzaktan görecek
  8. public float attackdistance; //ne kadar menzili var
  9. public float enemymovementspeed;
  10. public float damping;
  11. public Transform fpstarget;
  12. Rigidbody rb;
  13. //Renderer rend;
  14. // Use this for initialization
  15. void Start () {
  16. //rend = GetComponent<Renderer>();
  17. rb = GetComponent<Rigidbody>();
  18. }
  19.  
  20. // Update is called once per frame
  21. void FixedUpdate () {
  22. fpstargetdistance = Vector3.Distance(fpstarget.position,transform.position); //bu distance bulma fonksiyonu bunu unutma.
  23. if (fpstargetdistance < enemylookdistance )
  24. {
  25. //rend.material.color = Color.yellow;
  26. lookAtPlayer();
  27. //print("Look at the player please");
  28. }
  29. if (fpstargetdistance < attackdistance)
  30. {
  31. attackPlease();
  32. //Debug.Log("Attack");
  33. }
  34. }
  35. public void lookAtPlayer()
  36. {
  37. Quaternion rotation = Quaternion.LookRotation(fpstarget.position - transform.position);
  38. transform.rotation = Quaternion.Slerp(transform.rotation,rotation,Time.deltaTime * damping);
  39. }
  40. public void attackPlease()
  41. {
  42. //Debug.Log("Moving");
  43. rb.AddForce(transform.forward * enemymovementspeed);
  44. //rb.velocity = (transform.forward * enemymovementspeed);
  45. }
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement