void OnCollisionEnter(Collision collision) { IA_Skeleton_code script = holder.GetComponent <IA_Skeleton_code>(); if (IsHiting && collision.gameObject == script.GetTarget()) { Debug.Log("hit"); script.ApplyDamage(collision.gameObject); IsHiting = false; } }
// Update is called once per frame void Update() { if (Time.time > Skeleton.GetAllow_action()) { if (Skeleton.GetTarget() != null) { float Distance = Vector3.Distance(Skeleton.transform.position, Skeleton.GetTarget().transform.position); if (Distance > Skeleton.GetFightingRange()) { Skeleton.chase(); } else { if (Distance <= Skeleton.GetAttackRange()) { Skeleton.attack(); } else { if (Skeleton.GetFight() && Distance <= Skeleton.GetFightingRange()) { Skeleton.StartCoroutine("fighting"); } } } } } else { if (Skeleton.GetTarget() != null) { Vector3 Targetposition = new Vector3(Skeleton.GetTarget().transform.position.x, transform.position.y, Skeleton.GetTarget().transform.position.z); transform.LookAt(Targetposition); transform.position = Vector3.MoveTowards(transform.position, Skeleton.GetTarget().transform.position, 6 * Time.deltaTime); } } }
// Update is called once per frame void Update() { if (Skeleton.GetHealth() <= 0 && !drop) { animator.SetBool("Dead", true); Skeleton.GetTarget().gameObject.GetComponent <UnarmedCharacter>().Coins += 200; drop = true; return; } if (Skeleton.GetHealth() <= 0) { return; } pvBar.fillAmount = Skeleton.GetHealth() / MaxHp; if (Time.time > Skeleton.GetAllow_action()) { if (Skeleton.GetTarget() != null) { float Distance = Vector3.Distance(Skeleton.transform.position, Skeleton.GetTarget().transform.position); if (Distance > Skeleton.GetFightingRange()) { Skeleton.chase(); } else { if (Distance <= Skeleton.GetAttackRange()) { Skeleton.attack(); } else { if (Skeleton.GetFight() && Distance <= Skeleton.GetFightingRange()) { Skeleton.StartCoroutine("fighting"); } } } } } else { if (Skeleton.GetTarget() != null) { Vector3 Targetposition = new Vector3(Skeleton.GetTarget().transform.position.x, transform.position.y, Skeleton.GetTarget().transform.position.z); transform.LookAt(Targetposition); transform.position = Vector3.MoveTowards(transform.position, Skeleton.GetTarget().transform.position, 6 * Time.deltaTime); } } }
void OnTriggerEnter(Collider collision) { IA_Skeleton_code script = holder.GetComponent <IA_Skeleton_code>(); Debug.Log(collision.gameObject.tag + " test"); if (IsHiting && collision.gameObject == script.GetTarget()) { Debug.Log("hit"); script.ApplyDamage(collision.gameObject); if (Random.Range(0, 10) == 1) { collision.gameObject.GetComponent <UnarmedCharacter>().status = Status.Bleeding; if (collision.gameObject.GetComponent <PlayerStat>().coroutine != null) { StopCoroutine(collision.gameObject.GetComponent <PlayerStat>().coroutine); } collision.gameObject.GetComponent <PlayerStat>().SetDOT_Time(5); collision.gameObject.GetComponent <PlayerStat>().coroutine = StartCoroutine(collision.gameObject.GetComponent <PlayerStat>().GetOverTime()); } IsHiting = false; } }