// based off of DealDamage from DamageProjectile script
 private void DealDamage(AbstractHealth health)
 {
     if (health.Damage(gameObject, Damage))
     {
         Knockback(health.gameObject);
         //this.transform.position = new Vector2(1000000, 10000000);
         //Destroy(gameObject);
     }
 }
示例#2
0
    private void OnTriggerEnter2D(Collider2D other)
    {
        AbstractHealth health = other.gameObject.GetComponent <AbstractHealth>();

        if ((Hostile && health is PlayerHealth) || (!Hostile && health is EnemyHealth))
        {
            DealDamage(health);
        }
    }
    // derived from OnTriggerEnter2D in DamageProjectile script
    private void OnCollisionEnter2D(Collision2D collision)
    {
        GameObject other = collision.gameObject;

        if (other.name.Equals("Player"))
        {
            AbstractHealth health = other.GetComponent <AbstractHealth>();
            DealDamage(health);
        }
    }
示例#4
0
	public void EntityIsFound(Vector3 newPosition, AbstractHealth newHealth)
	{
		if((AttackSameType || health.GetType() != newHealth.GetType()) &&
		   (!targetPosition.HasValue || newHealth == targetHealth || 
		   Vector3.Distance(transform.position, newPosition) < Vector3.Distance(transform.position, targetPosition.Value)))
		{
			targetPosition = newPosition;
			targetHealth = newHealth;
		}
	}
示例#5
0
	void Awake()
	{
		anim = GetComponent<Animator>();
		nav = GetComponent<NavMeshAgent>();
		health = GetComponent<AbstractHealth>();
		if(KnowsPlayerPositionOnStart)
		{
			GameObject target = Cache.GetCachedGameObjectByTag(Tags.PLAYER);
			targetPosition = target.transform.position;
			targetHealth = target.GetComponent<AbstractHealth>();
		}
		else
		{
			targetPosition = null;
			targetHealth = null;
		}
		MoveLocked = false;
	}
示例#6
0
	void Awake()
	{
		spirakusMovement = GetComponentInParent<SpirakusMovement>();
		health = GetComponentInParent<AbstractHealth>();
	}
示例#7
0
	void Update()
	{
		if(!MoveLocked)
		{
			float distance = 0f;
			if(targetPosition.HasValue)
			{
				Vector3 currentPos = transform.position;
				Vector2 currentPos2 = new Vector2(currentPos.x, currentPos.z);
				Vector3 targetPos = targetPosition.Value;
				Vector2 targetPos2 = new Vector2(targetPos.x, targetPos.z);
				distance = Vector2.Distance(currentPos2, targetPos2);
			}
			
			if((targetHealth != null && targetHealth.IsDead()) || distance == 0f)
			{
				isMakingSound = false;
				targetPosition = null;
				targetHealth = null;
				anim.SetBool(AnimationIDs.IS_RUNNING, false);
				nav.Stop();
			}
			else
			{
				isMakingSound = true;
				anim.SetBool(AnimationIDs.IS_RUNNING, true);
				nav.SetDestination(targetPosition.Value);
				nav.Resume();
			}
		}
	}