using UnityEngine;
using System.Collections;
public class Enemy : MonoBehaviour {
public float playerDistance;
public Rigidbody2D playerRB2D;
public PlayerMovement playerMovement
{
get
{
return GetComponent();
}
}
// Use this for initialization
void Start() {
}
// Update is called once per frame
void Update() {
GetComponent<PlayerMovement>();
playerDistance = Vector3.Distance(playerRB2D.transform.position, transform.position);
if (playerMovement.isAttacking == true) //this line 29
{
if (playerMovement.isAttacking == true && playerDistance <= 1)
{
Debug.Log("Die");
Destroy(gameObject);
playerMovement.isAttacking = false;
}
}
}
}
using UnityEngine;
using System.Collections;
public class PlayerMovement : MonoBehaviour {
private Rigidbody2D rbody;
private Animator anim;
public bool isAttacking = false;
//public float enemyDistance;
//public Rigidbody2D enemyRB2D;
// Use this for initialization
void Start () {
rbody = GetComponent<Rigidbody2D>();
anim = GetComponent<Animator>();
}
// Update is called once per frame
void Update () {
Vector2 movement_vector = new Vector2(Input.GetAxisRaw("Horizontal") , Input.GetAxisRaw("Vertical"));
//if not zero must be moving
if (movement_vector != Vector2.zero)
{
anim.SetBool("isWalking", true);
anim.SetFloat("input_x", movement_vector.x);
anim.SetFloat("input_y", movement_vector.y);
}
else //sees if in idel or not changes anim
{
anim.SetBool("isWalking", false);
}
//movment by 1
rbody.MovePosition(rbody.position + movement_vector * Time.deltaTime);
//sets attack to true if space hit
if (Input.GetKeyDown(KeyCode.Space))
{
isAttacking = true;
Debug.Log("Attack");
}
//Makes anim attack
if (isAttacking == true)
{
anim.SetBool("isAttacking", true);
isAttacking = false;
}
else
{
anim.SetBool("isAttacking", false);
}
}
// checks if touch enemy and then if can attack then kill
//void OnTriggerEnter2D(Collider2D other)
//{
// {
// if (other.gameObject.tag == ("Enemy"))
// {
// enemyDistance = Vector3.Distance(enemyRB2D.transform.position, transform.position);
// Debug.Log("Touch");
// if (isAttacking == true && enemyDistance <= 1)
// {
// Debug.Log("Die");
// Destroy(other.gameObject);
// isAttacking = false;
// }
// }
// }
//}
}//end