// Use this for initialization void Start() { player = FindObjectOfType(typeof(Player)) as Player; playerDest = player.GetComponent<Destroyable>(); colorize = GetComponent<Colorize>(); maxHealth = playerDest.health; }
protected override void Start() { base.Start(); puncher = GetComponent<Puncher>(); player = GameObject.FindGameObjectWithTag("Player").GetComponent<Destroyable>(); shaman = GameObject.FindGameObjectWithTag("Shaman").GetComponent<Destroyable>(); }
// Use this for initialization void Start() { rigid = GetComponent<Rigidbody> (); stat = GetComponent<Destroyable> (); rigid.maxAngularVelocity = 20.0f; }
void ListenDestroy(Destroyable _destroyable) { m_CharacterRef = null; if (networkView != null && networkView.enabled) Network.RemoveRPCs(networkView.viewID); if (postDestroy != null) postDestroy (this, _destroyable.GetComponent<Character>()); }
public void AddScoreForDestroy(Destroyable destroyable) { AddScoreAndCoef(destroyable.GetCost(), true); if (!comboIsActive) { comboIsActive = true; comboNum++; } }
//Когда сработал триггер private void OnTriggerEnter2D(Collider2D other) { //Временная переменная, чтобы запомнить, кто вошел Respawnable respawnable = null; Destroyable destroyable = null; //Запоминаем, кто вошел и, если он имеет скрипт Respawnable if (other.gameObject.TryGetComponent(out respawnable) != false) { //То вызываем его метод Respawn() respawnable.Respawn(); } if (other.gameObject.TryGetComponent(out destroyable) != false) { destroyable.Destroy(); } }
void Shoot() { leftLine.SetPosition(0, left.position); rightLine.SetPosition(0, right.position); RaycastHit hit; if (Physics.Raycast(cockpitCam.transform.position, cockpitCam.transform.forward, out hit)) { leftLine.SetPosition(1, hit.point); rightLine.SetPosition(1, hit.point); Destroyable target = hit.transform.GetComponent <Destroyable>(); if (target != null) { if (target.health > 0.0f) { GameObject effect = Instantiate(impact, hit.point, Quaternion.LookRotation(hit.normal)); Destroy(effect, 4f); target.TakeDamage(damage); } else { GameObject effect = Instantiate(impact, hit.point, Quaternion.LookRotation(hit.normal)); effect.transform.localScale = new Vector3(200, 200, 200); Destroy(effect, 4f); target.Kill(); explosion.Play(); } } else { GameObject effect = Instantiate(impact, hit.point, Quaternion.LookRotation(hit.normal)); Destroy(effect, 4f); } Debug.Log(hit.transform.name); } else { leftLine.SetPosition(1, cockpitCam.transform.position + (cockpitCam.transform.forward * 1000)); rightLine.SetPosition(1, cockpitCam.transform.position + (cockpitCam.transform.forward * 1000)); } }
private void Update() { if (Input.GetMouseButtonDown(0)) { RaycastHit hit; if (Physics.Raycast(Camera.main.transform.position, Camera.main.transform.forward, out hit)) { Debug.DrawLine(Camera.main.transform.position, hit.point, Color.red); Actable actable = hit.transform.GetComponentInChildren <Actable>(); if (actable) { actable.Act(new string[] { "Foo" }); } Deformable deformable = hit.transform.GetComponentInChildren <Deformable>(); if (deformable) { deformable.Hit(hit, Camera.main.transform.forward * 4.0f); } Destroyable destroyable = hit.transform.GetComponentInChildren <Destroyable>(); if (destroyable) { destroyable.Explode(hit.point); } Terminatable terminatable = hit.transform.GetComponentInChildren <Terminatable>(); if (terminatable) { terminatable.Hit(Random.Range(0, 47), this.transform); } Damageable damageable; if ((damageable = hit.transform.GetComponent <Damageable>()) != null || (damageable = hit.transform.root.GetComponent <Damageable>()) != null) { damageable.Damage(hit); } Rigidbody rigidbody = hit.transform.GetComponentInChildren <Rigidbody>(); if (rigidbody) { rigidbody.AddForceAtPosition(Camera.main.transform.forward * 100.0f, hit.point); } } } }
public override void MonoCollisionEnter(GameObject gameObject, Collision2D coll) { if (IsActive() && coll != null && coll.gameObject != null && gameObject != null) { if (coll.gameObject.GetChar() != null && GetOwnerData().GetOwner().CanAttack(coll.gameObject.GetChar())) { if (!firstEnemyHit) { ApplyEffect(Owner, coll.gameObject, new EffectDamage(firstEnemyHitDamage)); firstEnemyHit = true; } ApplyEffects(Owner, coll.gameObject); } } if (spreadshotOnLand && gameObject.name.Equals("DodgeProjectile")) { if (coll.gameObject.Equals(GetOwnerData().GetBody())) { return; } Character ch = coll.gameObject.GetChar(); if (ch == null) { Destroyable d = coll.gameObject.GetComponent <Destroyable>(); if (d != null && !Owner.CanAttack(d)) { return; } } else if (!Owner.CanAttack(ch)) { return; } ApplyEffect(Owner, coll.gameObject, new EffectDamage(spreadshotDamage, 0)); DestroyProjectile(gameObject); } }
protected override void UseBeating() { RaycastHit hit; if (Physics.Raycast(new Ray(this.cameraTransform.position, this.cameraTransform.TransformDirection(Vector3.forward)), out hit, this.beatDistance)) { if (hit.transform.root == this.cameraTransform.root) return; Rigidbody rigidbody = hit.transform.root.GetComponent<Rigidbody>(); if (rigidbody != null) rigidbody.AddForce((hit.point - this.cameraTransform.position).normalized * this.player.strength); Terminatable terminatable = hit.transform.root.GetComponent<Terminatable>(); if (terminatable != null) terminatable.Hit(this.damage, hit, this.cameraTransform.root); else { Destroyable destroyable = hit.transform.root.GetComponent<Destroyable>(); if (destroyable != null) destroyable.Explode(hit.point); } } }
private void UpdateFixture() { if (destructible == null) { destructible = GetComponentInParent <Destroyable>(); } if (destructible == null) { DestroyFixture(); } else { var worldPosition = transform.TransformPoint(Offset); if (destructible.SampleAlpha(worldPosition) < 0.5f) { DestroyFixture(); } } }
protected override void OnCantMove <T>(T component) { switch (attack) { case Attack.AttL: animator.SetTrigger("AttL"); break; case Attack.AttB: animator.SetTrigger("AttB"); break; case Attack.AttR: animator.SetTrigger("AttR"); break; case Attack.AttU: animator.SetTrigger("AttU"); break; default: break; } if (component is Enemy) { Enemy hitEnemy = component as Enemy; hitEnemy.DamageEnemy(damage, onRight, gameObject); } else if (component is Destroyable) { Destroyable hitEnemy = component as Destroyable; hitEnemy.Damage(1); } else if (component is Boss) { Boss hitEnemy = component as Boss; hitEnemy.TakeHit(damage, gameObject); } }
public override void OnInspectorGUI() { serializedObject.Update(); Destroyable myTarget = (Destroyable)target; DrawDefaultInspector(); if (myTarget.SortObject == Destroyable.ObjectSort.Residence) { EditorGUILayout.PropertyField(buildingType); } else if (myTarget.SortObject == Destroyable.ObjectSort.Shop) { EditorGUILayout.PropertyField(shopType); } else if (myTarget.SortObject == Destroyable.ObjectSort.Vehicle) { EditorGUILayout.PropertyField(carType); } serializedObject.ApplyModifiedProperties(); }
protected virtual void OnEnable() { if (destructible == null) { destructible = GetComponent <Destroyable>(); } if (destructible.OnAlphaDataReplaced == null) { destructible.OnAlphaDataReplaced = new DestroyableEvent(); } if (destructible.OnAlphaDataModified == null) { destructible.OnAlphaDataModified = new DestroyableRectEvent(); } if (destructible.OnAlphaDataSubset == null) { destructible.OnAlphaDataSubset = new DestroyableRectEvent(); } if (destructible.OnStartSplit == null) { destructible.OnStartSplit = new DestroyableEvent(); } if (destructible.OnEndSplit == null) { destructible.OnEndSplit = new DestroyableListEvent(); } destructible.OnAlphaDataReplaced.AddListener(OnAlphaDataReplaced); destructible.OnAlphaDataModified.AddListener(OnAlphaDataModified); destructible.OnAlphaDataSubset.AddListener(OnAlphaDataSubset); destructible.OnStartSplit.AddListener(OnStartSplit); destructible.OnEndSplit.AddListener(OnEndSplit); if (child != null) { child.SetActive(true); } }
public override void ApplyEffect(Character source, GameObject target) { Vector3 targetPos = target.transform.position; Collider2D[] colls = Physics2D.OverlapCircleAll(targetPos, radius); foreach (Collider2D col in colls) { if (col != null && col.gameObject != null) { Character targetCh = col.gameObject.GetChar(); if (targetCh == null) { Destroyable d = col.gameObject.GetComponent <Destroyable>(); if (d != null && source.CanAttack(d)) { bool crit; int damage = source.CalculateDamage(Dmg + Random.Range(-RandomOffset, RandomOffset), null, SourceSkillObject, true, out crit); d.ReceiveDamage(source, damage); } } else { if (source.CanAttack(targetCh) || attackAll) { bool crit; int damage = source.CalculateDamage(Dmg + Random.Range(-RandomOffset, RandomOffset), targetCh, SourceSkillObject, true, out crit); source.OnAttack(targetCh); targetCh.ReceiveDamage(source, damage, SourceSkill, crit); } } } } }
protected virtual void Update() { cooldown -= Time.deltaTime; if (cooldown <= 0.0f) { cooldown = DelayPerHeal; if (destructible == null) { destructible = GetComponent <Destroyable>(); } if (snapshot.AlphaWidth == destructible.AlphaWidth && snapshot.AlphaHeight == destructible.AlphaHeight) { destructible.BeginAlphaModifications(); { for (var y = snapshot.AlphaHeight - 1; y >= 0; y--) { for (var x = snapshot.AlphaWidth - 1; x >= 0; x--) { var index = x + y * snapshot.AlphaWidth; var oldAlpha = destructible.AlphaData[index]; var newAlpha = snapshot.AlphaData[index]; if (oldAlpha != newAlpha) { newAlpha = (byte)Mathf.MoveTowards(oldAlpha, newAlpha, HealAmount); destructible.WriteAlpha(x, y, newAlpha); } } } } destructible.EndAlphaModifications(); } } }
public void Build(BotBuilder instructions) { _state = BotState.Building; _core = transform.Find("core").gameObject; _coreDest = _core.GetComponent <Destroyable>(); _baseName = instructions.platform; _ancres = GetComponent <Anchors>(); _rbody = GetComponent <Rigidbody>(); _rotationSpeed = instructions.rotationSpeed; _speed = instructions.speed; getDestroyables(gameObject); connectParts(instructions.listParts, _ancres.anchorsList); _totalHP = getHp(); if (isEdited) { transform.parent = MenuManager.instance.botContainer.transform; MenuManager.instance.ShowCasedBot = this; _rbody.constraints = RigidbodyConstraints.FreezePositionX | RigidbodyConstraints.FreezePositionZ;//| RigidbodyConstraints.FreezePositionY; _rbody.freezeRotation = true; Destroy(_rbody); } _state = BotState.Ready; }
private void Update() { if (IsFiring) { //int layerMask = 1 << (LayerMask.NameToLayer("Airplane") | LayerMask.NameToLayer("Enemy")); RaycastHit hit; if ((Time.time - lastTime) > DamageDelay && Physics.Raycast(FirePoint.position, FirePoint.TransformDirection(Vector3.forward), out hit, MaxDistance))//, layerMask)) { Destroyable foe = hit.transform.GetComponent <Destroyable>(); if (hit.transform.gameObject.layer == LayerMask.NameToLayer("Enemy")) { foe = hit.transform.parent.GetComponent <Destroyable>(); } if (foe) { foe.Damage(AttackPower); lastTime = Time.time; } } transform.Rotate(Vector3.forward, RotationSpeed * Time.deltaTime); } }
public override void Fire1() { if (canFireP) { laserTimer = 0; int layermask = 1 << 8; layermask = ~layermask; if (Physics.Raycast(transform.position, transform.forward, out hit, primaryRange, layermask)) { BaseShip hitShip = hit.collider.gameObject.GetComponent <BaseShip> (); Destroyable hitObstacle = hit.collider.gameObject.GetComponent <Destroyable> (); if (hitShip != null) { hitShip.Damage(damage, GetComponentInParent <BaseShip> ()); } else if (hitObstacle != null) { hitObstacle.Damage(damage); } } primaryTimer = 0; } }
private void CalcThunderTargets(Vector3 from, int range, Vector3 direction) { RaycastHit2D[] hits = Physics2D.RaycastAll(from, direction, range); foreach (RaycastHit2D hit in hits) { Character ch = hit.collider.gameObject.GetChar(); if (ch == null) { Destroyable d = hit.collider.gameObject.GetComponent <Destroyable>(); if (d != null && !Owner.CanAttack(d)) { continue; } } else if (!Owner.CanAttack(ch)) { continue; } // the only possible collisions are the projectile with target ApplyEffects(Owner, hit.collider.gameObject); } }
private void OnTriggerEnter(Collider other) { if (other.gameObject.layer == LayerMask.NameToLayer("Characters")) { Character otherChar = other.GetComponent <Character>(); if (otherChar) { if (otherChar != character) { otherChar.SetDamage(damage, direction, force, character); } } } if (other.gameObject.tag == "Destroyable") { Destroyable otherDestroy = other.GetComponent <Destroyable>(); if (otherDestroy) { otherDestroy.Shatter(true); } } }
public void AddBuilding(Destroyable destroyable) { AddBuilding(new Building(destroyable)); }
public Building(Destroyable destroyable) { this.name = destroyable.buildingName; this.score = destroyable.score; }
private void UpdatePhysx() { var an = _Game.PhysxEffectAnim; var phys = _Game.PhysxEffect.gameObject; _Game.PhysxEffect.position = upPos + mouseDir.normalized * 1.5f; if (CurrentWeapon.weaponType2 == WeaponType.physx) { if (Input.GetMouseButtonDown(1)) { an.PlayQueued("start", QueueMode.PlayNow); an.PlayQueued("loop"); phys.SetActive(true); } if (Input.GetMouseButtonUp(1)) { an.PlayQueued("release", QueueMode.PlayNow); if (holdingZombie != null) StartCoroutine(MoveObject(_Game.PhysxEffect, mouseDir.normalized * 5, .5f)); StartCoroutine(AddMethod(() => !an.isPlaying, delegate { phys.SetActive(false); })); } } if (isAttacking && CurrentCombo == Combo.spellCastUpper && CurrentWeapon.weaponType2 == WeaponType.physx) { if (holdingZombie == null) { Destroyable z = null; float oldDist = float.MaxValue; foreach (Destroyable z2 in _Game.destroyables) if (z2 is Zombie || z2 is Barrel) { if (z2.alive && z2.haveRigs && ((pos + mouseDir.normalized * 3) - z2.pos).magnitude < 3) { var dist = (pos - z2.pos).magnitude; if (dist < oldDist) { z = z2; oldDist = dist; } } } if (z != null) { holdingZombie = z; var zombie = z as Zombie; if (zombie != null) { zombie.Die(Vector3.zero, 0); foreach (Rigidbody a in zombie.rigidBodies) if (a != null) a.drag = 6; } else { if (!z.rigidbody) z.gameObject.AddComponent<Rigidbody>(); z.rigidbody.drag = 6; } } } else { var zombie = holdingZombie as Zombie; var barrel = holdingZombie as Barrel; if (zombie != null) { zombie.dieTime = Time.time; var vector3 = (pos + (zombie.Mass * Vector3.up + mouseDir.normalized * 1.5f) - zombie.spine.position); zombie.spine.rigidbody.velocity = ((vector3 * 200 + vector3.normalized * 40) * .1f); if (!Input.GetMouseButton(1)) StartCoroutine(zombie.ThrowZombie((_Player.mouseDir.normalized + Vector3.down * .3f) * 15)); } else if (barrel != null && barrel.enabled) { var vector3 = (pos + (Mass * Vector3.up + mouseDir.normalized * 1.5f) - barrel.transform.position); barrel.transform.rigidbody.velocity = ((vector3 * 200 + vector3.normalized * 40) * .05f); if (!Input.GetMouseButton(1)) { barrel.rigidbody.drag = 0; barrel.rigidbody.velocity = ((_Player.mouseDir.normalized + Vector3.down * .3f) * 15); } } if (!Input.GetMouseButton(1)) { currentCombo = 0; holdingZombie = null; } } } }
public void ListenDestroy(Destroyable _destroyable) { character = null; }
public override void MonoTriggerEnter(GameObject gameObject, Collider2D coll) { if (coll.gameObject.Equals(GetOwnerData().GetBody())) { return; } Character ch = coll.gameObject.GetChar(); ProjectileData d = GetProjectileData(gameObject); // if projectile was saved, it means special effects are to be applied if (d != null) { if (penetrateFriendly) { if (ch == null) { Destroyable des = coll.gameObject.GetComponent <Destroyable>(); if (des != null && !Owner.CanAttack(des)) { return; } } else if (!Owner.CanAttack(ch)) { return; } } // missile hit target if (d.target != null) { if (coll.gameObject.Equals(d.target.GetData().GetBody())) { d.target = null; } } if (penetrateTargets > 0 && d.penetratedTargets > 0 && (penetrateChangeDamage < 0 || penetrateChangeDamage > 0)) { ApplyEffects(Owner, coll.gameObject, false, d.penetratedTargets); } else { ApplyEffects(Owner, coll.gameObject); } bool destroy = false; if (penetrateTargets > 0) { // check if penetrated too many d.penetratedTargets++; if (d.penetratedTargets >= penetrateTargets) { destroy = true; } // find next target if (!destroy && navigateChangeTargetAfterHit) { float angle = d.proj.transform.rotation.eulerAngles.z; if (!navigateLookOnlyForward) { /*foreach (Collider2D hit in Physics2D.OverlapCircleAll(d.proj.transform.position, navigateAimArea)) * { * if (hit.gameObject.Equals(d.proj)) * continue; * * Character targetCh = hit.gameObject.GetChar(); * if (targetCh == null || !Owner.CanAttack(targetCh) || hit.gameObject.Equals(coll.gameObject)) * continue; * * d.target = targetCh; * AdjustToTarget(d); * break; * }*/ foreach (Collider2D c in Physics2D.OverlapCircleAll(d.proj.transform.position, navigateAimArea)) { if (c.gameObject.Equals(d.proj)) { continue; } Character targetCh = c.gameObject.GetChar(); if (targetCh == null || !Owner.CanAttack(targetCh) || c.gameObject.Equals(coll.gameObject)) { continue; } d.target = targetCh; AdjustToTarget(d); break; } } else { Vector3 direction = new Vector3(d.rb.velocity.x, d.rb.velocity.y); Vector3 perpend = Utils.GetPerpendicularVector(d.proj.transform.position, direction + d.proj.transform.position); foreach (Collider2D c in Physics2D.OverlapAreaAll(d.proj.transform.position + perpend * navigateAimArea / 2f + direction.normalized * navigateAimArea, d.proj.transform.position + perpend * (-navigateAimArea / 2f))) { if (c.gameObject.Equals(d.proj)) { continue; } Character targetCh = c.gameObject.GetChar(); if (targetCh == null || !Owner.CanAttack(targetCh) || c.gameObject.Equals(coll.gameObject)) { continue; } d.target = targetCh; AdjustToTarget(d); break; } } } } if (penetrateTargets == 0 || destroy) { if (explodeEffect) { GameObject explosion = CreateParticleEffect(explodeEffectName, false, gameObject.transform.position); explosion.GetComponent <ParticleSystem>().Play(); Object.Destroy(explosion, 2f); } DestroyProjectile(gameObject); } } else { if (penetrateFriendly) { if (ch == null) { Destroyable des = coll.gameObject.GetComponent <Destroyable>(); if (des != null && !Owner.CanAttack(des)) { return; } } else if (!Owner.CanAttack(ch)) { return; } } if (explodeEffect) { GameObject explosion = CreateParticleEffect(explodeEffectName, false, gameObject.transform.position); explosion.GetComponent <ParticleSystem>().Play(); Object.Destroy(explosion, 2f); } ApplyEffects(Owner, coll.gameObject); DestroyProjectile(gameObject); } }
private void Awake() { _destroyable = GetComponent <Destroyable>(); spriteRenderer.sprite = repairedSprite; }
private void OnTriggerEnter2D(Collider2D collision) { Destroyable bullet = collision.gameObject.GetComponent<Destroyable>(); Destroy(bullet.gameObject); }
private void Awake() { _destroyable = GetComponent <Destroyable>(); }
void Awake() { destroyable = GetComponent<Destroyable>(); }
private void ZombieSetLife(Destroyable destroyable, float damage, Vector3 vector3, int forse) { bool knockout = false; var zombie = destroyable as Zombie; if (zombie!=null) { zombie.Cut(vector3, forse, false, false, !zombie.skeleton); if (Random.value < _Hud.stats.Knockback / 100f) { _Game.Text("Отлет", zombie.upPos, Color.yellow, 2); knockout = true; } if (Random.value < _Hud.stats.SlowDown / 100f) { _Game.Text("Замедление", zombie.upPos, Color.blue, 2); zombie.slowDownTime = Time.time; } if (Random.value < _Hud.stats.Crtitical / 100f) { _Game.Text("Критический", zombie.upPos, Color.red, 2); damage *= 2; } } destroyable.SetLife(damage, vector3, forse, knockout); }
private void DestroyableOnDestroyed(Destroyable destroyable) { repairedVariant.SetActive(false); brokenVariant.SetActive(true); }
public void AddEnergy(Destroyable destroyable) { energy = Mathf.Clamp(energy + destroyable.GetRewardEnergy(), 0,maxEnergy); }
private void OnTargetDestroyed() { Target = null; }
// Use this for initialization void Start() { _destroyable = transform.parent.GetComponent<Destroyable>(); }
private void DestroyableOnDestroyed(Destroyable destroyable) { spriteRenderer.gameObject.SetActive(false); brokenVariant.SetActive(true); }
private void DestroyableOnDestroyed(Destroyable destroyable) { CurrDestructionPoints += destroyable.AwardedDestructionPoints; RecalculateDestructionValue(); }
void ListenCharacterDestroy(Destroyable _destroyable) { character = null; Destroy(gameObject); }
public void SetTarget(Destroyable target) { currentVictim = target; }
private void UpdatePhysx() { var an = _Game.PhysxEffectAnim; var phys = _Game.PhysxEffect.gameObject; _Game.PhysxEffect.position = upPos + mouseDir.normalized * 1.5f; if (CurrentWeapon.weaponType2 == WeaponType.physx) { if (Input.GetMouseButtonDown(1)) { an.PlayQueued("start", QueueMode.PlayNow); an.PlayQueued("loop"); phys.SetActive(true); } if (Input.GetMouseButtonUp(1)) { an.PlayQueued("release", QueueMode.PlayNow); if (holdingZombie != null) { StartCoroutine(MoveObject(_Game.PhysxEffect, mouseDir.normalized * 5, .5f)); } StartCoroutine(AddMethod(() => !an.isPlaying, delegate { phys.SetActive(false); })); } } if (isAttacking && CurrentCombo == Combo.spellCastUpper && CurrentWeapon.weaponType2 == WeaponType.physx) { if (holdingZombie == null) { Destroyable z = null; float oldDist = float.MaxValue; foreach (Destroyable z2 in _Game.destroyables) { if (z2 is Zombie || z2 is Barrel) { if (z2.alive && z2.haveRigs && ((pos + mouseDir.normalized * 3) - z2.pos).magnitude < 3) { var dist = (pos - z2.pos).magnitude; if (dist < oldDist) { z = z2; oldDist = dist; } } } } if (z != null) { holdingZombie = z; var zombie = z as Zombie; if (zombie != null) { zombie.Die(Vector3.zero, 0); foreach (Rigidbody a in zombie.rigidBodies) { if (a != null) { a.drag = 6; } } } else { if (!z.rigidbody) { z.gameObject.AddComponent <Rigidbody>(); } z.rigidbody.drag = 6; } } } else { var zombie = holdingZombie as Zombie; var barrel = holdingZombie as Barrel; if (zombie != null) { zombie.dieTime = Time.time; var vector3 = (pos + (zombie.Mass * Vector3.up + mouseDir.normalized * 1.5f) - zombie.spine.position); zombie.spine.rigidbody.velocity = ((vector3 * 200 + vector3.normalized * 40) * .1f); if (!Input.GetMouseButton(1)) { StartCoroutine(zombie.ThrowZombie((_Player.mouseDir.normalized + Vector3.down * .3f) * 15)); } } else if (barrel != null && barrel.enabled) { var vector3 = (pos + (Mass * Vector3.up + mouseDir.normalized * 1.5f) - barrel.transform.position); barrel.transform.rigidbody.velocity = ((vector3 * 200 + vector3.normalized * 40) * .05f); if (!Input.GetMouseButton(1)) { barrel.rigidbody.drag = 0; barrel.rigidbody.velocity = ((_Player.mouseDir.normalized + Vector3.down * .3f) * 15); } } if (!Input.GetMouseButton(1)) { currentCombo = 0; holdingZombie = null; } } } }
// Use this for initialization void Start() { destroyable = GetComponent<Destroyable>(); }
// Update is called once per frame void Update() { // Check if player is looking at interactable RaycastHit interactHit; Ray shootRay = playerCamera.ViewportPointToRay(new Vector3(0.5f, 0.5f, 0)); if (Physics.Raycast(shootRay, out interactHit, interactRange, interactMask, QueryTriggerInteraction.Collide)) { Interactable target = interactHit.collider.GetComponent <Interactable>(); if (target != null) { target.Select(); if (Input.GetButtonDown("Interact")) { target.Interact(); } } } // Check if player is shooting if (Input.GetButtonDown("Fire")) { bool canShoot = gun.Fire(); RaycastHit gunHit; if (canShoot) { // Shooting disables visor visor.SetVisor(false); if (Physics.Raycast(shootRay, out gunHit, 100, shootMask, QueryTriggerInteraction.Collide)) { // Probably better to have some target component with an invokable event instead HitParticleSpawner particleSpawner = gunHit.collider.GetComponent <HitParticleSpawner>(); Enemy enemy = gunHit.collider.GetComponentInParent <Enemy>(); Destroyable destroyable = gunHit.collider.GetComponent <Destroyable>(); // Spawn particles if (particleSpawner != null) { particleSpawner.Shoot(gunHit, shootRay); } // Damage enemy if (enemy != null) { bool headshot = gunHit.collider.CompareTag("Head"); float damage = gun.damage; if (headshot) { damage *= gun.headshotBonus; } enemy.InflictDamage(damage); } // Destroy object if (destroyable != null) { destroyable.Shoot(gun.damage); } } } } }
void Remove(Destroyable _destroyable) { Remove(_destroyable.GetComponent<Character>().id); }