// Update is called once per frame void Update() { //snyc speed nav.speed = myStats.moveSpeed; if (!myStats.IsAlive()) { Destroy(gameObject); } if (targetPlayer == null) { TargetClosestPlayer(); } nav.SetDestination(targetPlayer.transform.position); //attack if in range and cooldown has passed if (!firstUpdate && nav.remainingDistance < attackRange && Time.time > nextAttackAt) { targetPlayer.GetComponent <StatsHandler>().ChangeHealth(-attackDamage); //set when enemy can next attack nextAttackAt = Time.time + attackCooldown; } firstUpdate = false; }
void Update() { //Spell Stuff if (!isSecondaryCasting) { isPrimaryCasting = playerIn.GetAxisAsButton("Primary Spell") > 0; } if (!isPrimaryCasting) { isSecondaryCasting = playerIn.GetButton("Secondary Spell"); } if (playerIn.GetAxisAsButtonDown("Primary Spell") < 0 && !(isPrimaryCasting || isSecondaryCasting)) { shotgun.fire(); } if (playerIn.GetAxisAsButtonDown("Primary Spell") > 0 && !isSecondaryCasting) { primarySpell.PressSpell(gameObject); } if (playerIn.GetAxisAsButtonUp("Primary Spell") > 0 && !isSecondaryCasting) { primarySpell.ReleaseSpell(gameObject); } if (playerIn.GetButtonDown("Secondary Spell") && !isPrimaryCasting) { secondarySpell.PressSpell(gameObject); } if (playerIn.GetButtonUp("Secondary Spell") && !isPrimaryCasting) { secondarySpell.ReleaseSpell(gameObject); } if (playerIn.GetButtonDown("Disarm")) { if (playerIn.GetAxisAsButton("Primary Spell") > 0) { primarySpell.DisarmSpell(); } else if (playerIn.GetButton("Secondary Spell")) { secondarySpell.DisarmSpell(); } } if (playerIn.GetButtonDown("Fire")) { myStats.AddElementalEffect(gameObject.AddComponent <ManaRegenEffect>()); } //Movement characterController.Move(playerIn.GetMoveAxis() * myStats.moveSpeed * Time.deltaTime); //Look Direction Quaternion rotation = new Quaternion(); Vector3 axisIn = playerIn.GetLookAxis(); if (axisIn.magnitude > 0) { //Debug.Log(axisIn.magnitude + ": (" + axisIn.x + ", " + axisIn.y + ", " + axisIn.z + ")" ); //Debug TODO: Remove rotation.SetLookRotation(axisIn.normalized); transform.rotation = rotation; } if (!myStats.IsAlive()) { Destroy(gameObject); } }