Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //to follow and rotate towards player IN ENEMYAIS SCRIPT
- void DetectPlayer()
- {
- //finds the distance
- float distanceToPlayer = Vector3.Distance(player.position, transform.position);
- if (followDistance >= distanceToPlayer && distanceToPlayer > 1)
- {
- //if distance is at the correct range move towards player
- transform.position = Vector2.MoveTowards(transform.position, player.position, speed * Time.deltaTime);
- //if in attacking range attack
- if(distanceToPlayer <= attackDistance)
- {
- Debug.Log("Test1");
- if (Time.time > lastAttackTime + attackDelay)
- {
- //accessing the Player class function checkplayerstate to damage the player
- player.SendMessage("CheckPlayerState", damage);
- Debug.Log("Hit for " + damage + " damage");
- lastAttackTime = Time.time;
- }
- }
- }
- //detects the damage coming into the player IN THE PLAYER SCRIPT
- //public function so its accessable in the enemies script
- public void CheckPlayerState(float incdmg)
- {
- float defense;
- health -= incdmg;
- if (health <= 0)
- {
- Debug.Log("Hit");
- Destroy(this.gameObject);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement