// Update is called once per frame void Update() { SetDistances(); if (myActor.equippedItemGameobject == null) { if (closestWeapon == null || closestWeapon.isOut) { agent.SetDestination(this.transform.position); //no weapons avail return; } if (Vector3.Distance(closestWeapon.gameObject.transform.position, gameObject.transform.position) < 1.2) { myActor.PickupItem(closestWeapon.gameObject); equippedWeapon = myActor.equippedItemGameobject.GetComponent <WeaponContainer>(); return; } else { agent.SetDestination(closestWeapon.gameObject.transform.position); } } else { //we should have a weapon if (foe == null) { if (debugging) { print("no enemy found"); } agent.SetDestination(this.transform.position); return; } if (Vector3.Distance(foe.gameObject.transform.position, this.gameObject.transform.position) < myActor.GetWeapon().range) { gameObject.transform.LookAt(foe.gameObject.transform.position); agent.SetDestination(this.transform.position); //done moving RaycastHit hit; if (Physics.Raycast(this.transform.position, this.gameObject.transform.forward, out hit, myActor.GetWeapon().range, 1 << 9)) { if (hit.collider.gameObject == foe.GetComponent <Collider>().gameObject) { equippedWeapon.Use(); } } } else { gameObject.transform.LookAt(foe.gameObject.transform.position); this.agent.SetDestination(foe.gameObject.transform.position); } } }
// Update is called once per frame void Update() { if (myActor.equippedItemGameobject == null) { SetDistancesItems(); if (closestWeapon == null || closestWeapon.isOut) { agent.SetDestination(this.transform.position); //no weapons avail return; } if (Vector3.Distance(closestWeapon.gameObject.transform.position, gameObject.transform.position) < 1.2 && myActor.health > 0) { myActor.PickupItem(closestWeapon.gameObject); equippedWeapon = GameManager.linkedWeapons[myActor.equippedItemGameobject]; return; } else { agent.SetDestination(closestWeapon.gameObject.transform.position); } } else { SetDistancesEnemies(); //we should have a weapon if (foe == null) { if (debugging) { print("no enemy found"); } agent.SetDestination(this.transform.position); return; } if (Vector3.Distance(foe.gameObject.transform.position, this.gameObject.transform.position) < myActor.GetWeapon().range) { Vector3 targetPosition = new Vector3(foe.transform.position.x, this.transform.position.y, foe.transform.position.z); gameObject.transform.LookAt(targetPosition); agent.SetDestination(this.transform.position); //done moving RaycastHit hit; if (Physics.Raycast(this.transform.position, this.gameObject.transform.forward, out hit, myActor.GetWeapon().range, 1 << 9)) { if (hit.collider.gameObject == foe.gameObject) { equippedWeapon.Use(); } } } else { Vector3 targetPosition = new Vector3(foe.transform.position.x, this.transform.position.y, foe.transform.position.z); gameObject.transform.LookAt(targetPosition); this.agent.SetDestination(foe.gameObject.transform.position); } } }
IEnumerator Attack() { weaponContainer.Use(); yield return(new WaitForSeconds(1)); } // Grabs the WC and uses the Swing method.