Advertisement
Guest User

Untitled

a guest
Dec 14th, 2019
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.37 KB | None | 0 0
  1.     //to follow and rotate towards player  IN ENEMYAIS SCRIPT
  2.     void DetectPlayer()
  3.     {
  4.         //finds the distance
  5.         float distanceToPlayer = Vector3.Distance(player.position, transform.position);
  6.         if (followDistance >= distanceToPlayer && distanceToPlayer > 1)
  7.         {
  8.             //if distance is at the correct range move towards player
  9.             transform.position = Vector2.MoveTowards(transform.position, player.position, speed * Time.deltaTime);
  10.  
  11.             //if in attacking range attack
  12.             if(distanceToPlayer <= attackDistance)
  13.             {
  14.                 Debug.Log("Test1");
  15.                 if (Time.time > lastAttackTime + attackDelay)
  16.                 {
  17.                     //accessing the Player class function checkplayerstate to damage the player
  18.                     player.SendMessage("CheckPlayerState", damage);
  19.                     Debug.Log("Hit for " + damage + " damage");
  20.                     lastAttackTime = Time.time;
  21.                 }
  22.             }
  23.         }
  24.  
  25. //detects the damage coming into the player IN THE PLAYER SCRIPT
  26. //public function so its accessable in the enemies script
  27.  public void CheckPlayerState(float incdmg)
  28.     {
  29.         float defense;
  30.  
  31.         health -= incdmg;
  32.  
  33.         if (health <= 0)
  34.         {
  35.             Debug.Log("Hit");
  36.             Destroy(this.gameObject);
  37.         }
  38.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement