void Update() { if (Input.GetButton("Fire1")) { Weapon weapon = GetComponentInChildren <Weapon>(); if (weapon) { bool used = false; foreach (var entity in weapon.entitiesInRange) { if (entity.isPlayer) { continue; } used |= weapon.UseOn(entity); } if (used) { RandomizedSounds.Play(transform, RandomizedSounds.ATTACK); } // Draw animation even if we hit nothing weapon.UseOn(null); } } }
private void Update() { updateTime -= Time.deltaTime; if (updateTime < 0) { RandomizedSounds.TriggerUpdate(); updateTime = 0.3f; } }
private void OnTriggerEnter2D(Collider2D other) { if (other.GetComponent <PlayerMovement>()) { GetComponentInParent <EnemyMovement>().isAggressive = true; Animator animator = GetComponentInParent <Animator>(); if (AnimationHelper.hasParameter(animator, AGGRESSIVE)) { animator.SetBool(AGGRESSIVE, true); } RandomizedSounds.Play(gameObject.transform.parent, RandomizedSounds.SPOTTED); aggressionCounter++; } }
public void TakeDamage(int damageReceived) { int damage = damageReceived; if (isPlayer) { damage *= PlayerSetup.damageMultiplier; } Armor armor = GetComponentInChildren <Armor>(); if (armor) { damage = (int)(damage * armor.damagePercentage / 100f); } if (damage > 0) { health -= damage; Transform newTransform = Instantiate(onDamagePrefab, transform); newTransform.Translate(Random.Range(splatterArea.xMin, splatterArea.xMax), Random.Range(splatterArea.yMin, splatterArea.yMax), 0); Animation animator = newTransform.GetComponent <Animation>(); if (animator) { animator.wrapMode = WrapMode.Once; } if (!isPlayer) { RandomizedSounds.Play(transform, RandomizedSounds.HURT); } //TODO: Play some animations / sound / whatever } }
private void Update() { if (isAggressive) { bool used = false; AbstractWeapon weapon = GetComponentInChildren <AbstractWeapon>(); if (weapon) { foreach (var entity in weapon.entitiesInRange) { if (entity.isPlayer) { used |= weapon.UseOn(entity); } } } if (used) { RandomizedSounds.Play(transform, RandomizedSounds.ATTACK); } } }
// Update is called once per frame private void FixedUpdate() { float vertical = Input.GetAxis("Vertical"); float horizontal = Input.GetAxis("Horizontal"); Rigidbody2D rigidbody = GetComponentInChildren <Rigidbody2D>(); if (!Mathf.Approximately(vertical, 0f) || !Mathf.Approximately(horizontal, 0f)) { rigidbody.velocity = new Vector2(horizontal, vertical) * movementSpeed; } else { rigidbody.velocity = Vector2.zero; } bool idle = Mathf.Approximately(vertical, 0f) && Mathf.Approximately(horizontal, 0f); bool right = horizontal > 0; bool left = horizontal < 0; bool forward = vertical < 0; bool backward = vertical > 0; int direction = forward ? 0 : left ? 1 : backward ? 2 : 3; foreach (Animator animator in GetComponentsInChildren <Animator>()) { if (idle) { if (AnimationHelper.hasParameter(animator, IDLE)) { animator.SetBool(IDLE, true); } } else { RandomizedSounds.Play(transform, RandomizedSounds.MOVEMENT); if (AnimationHelper.hasParameter(animator, IDLE)) { animator.SetBool(IDLE, false); } if (AnimationHelper.hasParameter(animator, DIRECTION)) { animator.SetInteger(DIRECTION, direction); } if (AnimationHelper.hasParameter(animator, SHOW_RIGHT)) { if (right) { animator.SetBool(SHOW_RIGHT, true); } else { animator.SetBool(SHOW_RIGHT, false); } } lastDirection = direction; } } AbstractWeapon weapon = GetComponentInChildren <AbstractWeapon>(); HandleWeapon(weapon, idle, idle ? lastDirection : direction); }