public void Fire(Transform target, UnitCombat owner) { col = GetComponent <Collider>(); rigid = GetComponent <Rigidbody>(); var rend = GetComponent <Renderer>(); var trail = GetComponent <TrailRenderer>(); this.target = target; rend.material.color = SelectionManager.instance.teamColors[owner.TeamIndex]; trail.startColor = trail.endColor = SelectionManager.instance.teamColors[owner.TeamIndex]; startPos = transform.position; this.owner = owner; col.enabled = false; if (ArmingTime == 0) { col.enabled = true; } else { StartCoroutine(EnableCollider()); } rigid.AddForce(vecToTarget * 10 * Magnetism); rigid.useGravity = false; StartCoroutine(SelfDestruct()); }
public override bool Complete(Selectable sel) { if ((targetLocation - sel.transform.position).magnitude < stopDistance) { if (prod.TeamIndex == sel.TeamIndex) { prod.UpdateBuildProgress(0.3f); } else { CaptureableUnitProducer capturablePro = (CaptureableUnitProducer)prod; if (sel.TeamIndex == 0) { capturablePro.UpdatePlayerCaptureProgress(0.34f); } else { capturablePro.UpdateEnemyCaptureProgress(0.34f); } } UnitCombat unit = sel.transform.GetComponentInChildren <UnitCombat>(); if (unit) { unit.selfDamage(1000); } return(true); } return(false); }
public void SetTarget(GameObject tar) { target = tar; if (target != null) { UnitStatSystem tarStat = target.GetComponent <UnitStatSystem>(); if (tarStat != null) { foreach (GameObject uni in unitList) { UnitCombat com = uni.GetComponent <UnitCombat>(); com.SetTarget(tarStat); } } UnitGroupSystem tarGro = target.GetComponent <UnitGroupSystem>(); if (tarGro != null) { foreach (GameObject uni in unitList) { UnitCombat com = uni.GetComponent <UnitCombat>(); UnitStatSystem tarLitStat = tarGro.GetUnitList()[Random.Range(0, tarGro.GetUnitList().Count)].GetComponent <UnitStatSystem>(); com.SetTarget(tarLitStat); } } } }
public override void StopInteract(Interactable interactor) { isAttacking = false; Debug.Log("STOPPING " + interactor); base.StopInteract(interactor); interactorCombat.StopAttack(); interactorCombat = null; }
public override void StopInteract(Interactable interactor) { base.StopInteract(interactor); isAttacking = false; base.StopInteract(interactor); enemyCombat.StopAttack(); enemyCombat = null; }
public override void Interact(Interactable interactor) { isAttacking = true; interactorCombat = interactor.GetComponent <UnitCombat> (); if (interactorCombat == null) { Debug.Log(" NULL INTERACTOR "); return; } interactorCombat.Attack(myStats); base.Interact(interactor); }
public override void Interact(Interactable interactor) { isAttacking = true; enemyCombat = interactor.GetComponent <UnitCombat> (); if (enemyCombat == null) { Debug.Log(" NULL INTERACTOR "); return; } enemyCombat.Attack(targetStats: myStats); Debug.Log("Attacking Bldg"); base.Interact(interactor); }
// Start is called before the first frame update void Awake() { healthScript = gameObject.GetComponent <UnitHealth>(); combatScript = gameObject.GetComponent <UnitCombat>(); destinationSetter = gameObject.GetComponent <AIDestinationSetter>(); bodyParts = gameObject.GetComponentsInChildren <UnitBodyPart>().ToList(); weapons = gameObject.GetComponentsInChildren <Weapon>().ToList(); healthScript.ThisUnit = this; combatScript.ThisUnit = this; bodyParts.ForEach(x => x.ThisUnit = this); weapons.ForEach(x => x.ThisUnit = this); }
public void SetAutoAttaack(bool set) { foreach (GameObject uni in unitList) { if (uni != null) { UnitCombat com = uni.GetComponent <UnitCombat>(); if (com != null) { com.SetAutoATK(set); } } } }
// Use this for initialization void Start() { checkColPoint = this.gameObject; _charController = GetComponent <CharacterController>(); if (isNeedStat) { stat = GetComponent <UnitStatSystem>(); } if (needAni) { _animator = GetComponent <Animator>(); } if (canFight) { combStat = GetComponent <UnitCombat>(); } }
private void OnTriggerEnter(Collider other) { UnitCombat combat = other.GetComponent <UnitCombat>(); if (combat != null && combat.TeamIndex != unit.TeamIndex) { if (!unit.isAttacking) { ArtilleryUnit au = unit as ArtilleryUnit; ShieldUnit su = combat.gameObject.GetComponent <ShieldUnit>(); if (au != null && su != null) { return; } unit.PreemptOrder(new AttackOrder(other.transform)); } } }
private void OnCollisionEnter(Collision collision) { Transform hitObj = collision.transform; UnitCombat combat = hitObj.gameObject.GetComponent <UnitCombat>(); if (combat == owner) { return; } if (combat != null) { if (owner.isBuffed == 1) { combat.Damage(Damage + 3.0f); } else { combat.Damage(Damage); } } else { var parentComb = hitObj.parent.gameObject.GetComponent <ShieldUnit>(); if (parentComb != null && (parentComb.TeamIndex == owner.TeamIndex || (parentComb.transform.position - startPos).magnitude < parentComb.Radius)) { Physics.IgnoreCollision(collision.collider, col, true); return; } } if (OnImpact != null) { OnImpact.Invoke(); } if (explosionPrefab != null) { var obj = Instantiate(explosionPrefab, transform.position, Quaternion.identity) as GameObject; } Destroy(gameObject); }
public void Damage(float ammount) { CurrentHealth -= ammount; CurrentHealth = Mathf.Clamp(CurrentHealth, 0, MaxHealth); if (OnDamage != null) { OnDamage.Invoke(ammount); } if (OnHealthChanged != null) { OnHealthChanged.Invoke(CurrentHealth / MaxHealth); } if (CurrentHealth == 0) { if (OnDeath != null) { OnDeath.Invoke(); if (unit == null) { return; } if (unit.TeamIndex == 1) { foreach (var factory in UnitProducer.FactoryList) { if ((factory.TeamIndex != unit.TeamIndex) && (!factory.convertable)) { UnitCombat comb = factory.GetComponent <UnitCombat>(); if (comb == null) { continue; } comb.recoverHealth(10.0f); } } } } Destroy(unit.gameObject); } }
public AttackOrder(Transform target) { this.target = target; this.targetCombat = target.gameObject.GetComponent <UnitCombat>(); location = targetCombat.transform.position; }
void Start() { agent = GetComponent <NavMeshAgent>(); combat = GetComponent <UnitCombat>(); }
// Update is called once per frame void Update() { if (isSelected) { selectorCircle.SetActive(true); } else { selectorCircle.SetActive(false); } for (int i = 0; i < unitList.Count; i++) { GameObject uniChe = null; uniChe = unitList[i]; if (uniChe) { UnitStatSystem uniSta = uniChe.GetComponent <UnitStatSystem>(); uniSta.SetSelected(isSelected); } } if (target != null) { Vector3 targetPos = new Vector3(target.transform.position.x, 0, target.transform.position.z); Vector3 groPos = new Vector3(transform.position.x, 0, transform.position.z); UnitMove mover = GetComponent <UnitMove>(); if (Vector3.Distance(targetPos, groPos) >= atkRange) { if (!mover.GetIsColEvd()) { mover.OrderMove(targetPos); } } else { if (!mover.GetIsColEvd()) { mover.OrderMove(Vector3.one); } } } else { for (int i = 0; i < unitList.Count; i++) { GameObject uniObj = null; uniObj = unitList[i]; GameObject posObj = null; posObj = pointList[i]; if (uniObj != null && posObj != null) { Vector3 uniPos = new Vector3(uniObj.transform.position.x, 0, uniObj.transform.position.z); Vector3 posPos = new Vector3(posObj.transform.position.x, 0, posObj.transform.position.z); UnitMove uni = uniObj.GetComponent <UnitMove>(); UnitCombat com = uniObj.GetComponent <UnitCombat>(); UnitStatSystem star = uniObj.GetComponent <UnitStatSystem>(); if (star.GetAlive()) { star.SetSelected(isSelected); if (!com.HaveTarget()) { if (Vector3.Distance(uniPos, posPos) > 1) { if (!uni.GetIsColEvd()) { uni.OrderMove(posObj.transform.position); com.SetAutoATK(false); } } else { if (!uni.GetIsColEvd()) { uni.OrderMove(Vector3.one); com.SetAutoATK(true); } } } else { Vector3 groPos = new Vector3(transform.position.x, 0, transform.position.z); if (Vector3.Distance(groPos, uniPos) >= maxFollow) { com.SetTarget(null); com.SetAutoATK(false); } } } } else { unitList.Remove(uniObj); pointList.Remove(posObj); Destroy(posObj.gameObject); } } } if (unitList.Count <= 0) { Destroy(this.gameObject); } }
// Update is called once per frame void Update() { RaycastHit hit; Physics.Raycast(camera.transform.position, camera.transform.forward, out hit, 1000f, LayerMask.GetMask("Default")); if (hit.transform) { cursor.position = hit.point; } else { cursor.position = camera.transform.position + camera.transform.forward * 1000f; } if (lazersOn) { FaceLazers[0].SetPosition(0, transform.position - transform.right * lazerOffset); FaceLazers[1].SetPosition(0, transform.position + transform.right * lazerOffset); FaceLazers[0].SetPosition(1, cursor.position); FaceLazers[1].SetPosition(1, cursor.position); if (count++ % perframes == 0) { Instantiate(lazerExplosion, cursor.position, Quaternion.identity); } var hits = Physics.SphereCastAll(camera.transform.position, 1, camera.transform.forward, 1000f, LayerMask.GetMask("Units")); foreach (var h in hits) { if (hit.transform) { UnitCombat comb = h.transform.GetComponent <UnitCombat>(); UnitBase unit = h.transform.GetComponent <UnitBase>(); print(hit); print(comb); print(unit); if (unit != null && comb != null && unit.TeamIndex == 1 && unit as UnitProducer == null) { comb.Damage(lazerDamage); } } } } if (Input.GetMouseButtonDown(0)) // Did the player just click down the left mouse? { clickStartPos = Input.mousePosition; } if (Input.GetMouseButtonUp(0)) // Did the player just click down the left mouse? { if (Vector2.Distance(clickStartPos, Input.mousePosition) > dragThreshold) { OnBoxSelect(clickStartPos, Input.mousePosition); } else { OnLeftClick(camera.ScreenPointToRay(Input.mousePosition)); } } if (Input.GetMouseButtonDown(1)) // Did the player just click down the right mouse? { OnRightClick(camera.ScreenPointToRay(Input.mousePosition)); } }
private void Start() { UnitCombat = GetComponentInParent <UnitCombat>(); }
protected override void Start() { base.Start(); combat = GetComponentInParent <UnitCombat>(); }
// Update is called once per frame void Update() { if (Input.GetKeyDown(KeyCode.G)) { cameraScripts.toggleLock(); } if (Input.GetKeyDown(KeyCode.V)) { HealthBar[] healthBars = FindObjectsOfType(typeof(HealthBar)) as HealthBar[]; foreach (HealthBar bar in healthBars) { bar.toggleVisibility(); } } if (Input.GetKeyDown(KeyCode.H)) { if (lichMana >= Tuner.LICH_ABILITY_HEAL_COST) { bool healed = false; foreach (GameObject c in partySystem.aliveCharacters) { if (c != null && c.GetComponent <UnitCombat>() != null) { if (c.GetComponent <UnitCombat>().getHealth() != c.GetComponent <UnitCombat>().getMaxHealth()) { foreach (GameObject b in partySystem.aliveCharacters) { if (b != null && b.GetComponent <UnitCombat>() != null) { b.GetComponent <UnitCombat>().takeDamage(-(b.GetComponent <UnitCombat>().getMaxHealth() * Tuner.LICH_ABILITY_HEAL_AMOUNT), null); } } healed = true; break; } } } if (healed) { lichMana -= Tuner.LICH_ABILITY_HEAL_COST; } } } if (Input.GetKeyDown(KeyCode.F1)) { keyboardHelp.SetActive(!keyboardHelp.activeSelf); } ///////////////////////////////////// /// LICH ABILITIES ///////////////////////////////////// float manaScale = lichMana / 100f; manaScale = Mathf.Clamp(manaScale, 0, 1f); lichManaBar.localScale = new Vector3(lichManaBarScaleX * manaScale, lichManaBar.localScale.y, lichManaBar.localScale.z); ///////////////////////////////////// /// CHARACTER ABILITIES ///////////////////////////////////// for (int i = 0; i < 8; i++) { wasTargeting[i] = targeting[i]; } GameObject character = null; for (int i = 0; i < 8; i++) { int characterID = Mathf.FloorToInt((i * 0.5f) + 1); int abilityID = (i % 2); UnitCombat unitCombat = partySystem.getCharacter(characterID).GetComponent <UnitCombat>(); if ((Input.GetKeyDown(Tuner.KEYS_CHARACTER_ABILITY[i]) || HUDCast[i] == true) && !Input.GetKey(KeyCode.LeftShift) && unitCombat.isAlive()) { if (unitCombat.canCastAbility(abilityID, Vector2.zero, false)) { targeting[i] = true; //shift = false; } } if (targeting[i] && (Input.GetMouseButtonDown(1) || !Input.GetKey(Tuner.KEYS_CHARACTER_ABILITY[i])) && HUDCast[i] == false) { if (!Input.GetKey(Tuner.KEYS_CHARACTER_ABILITY[i])) { unitCombat.castAbilityInSlot(abilityID, CameraScripts.getCurrentMousePos()); } targeting[i] = false; //shift = false; } } /* * if (i < 4) * { * if (targeting[i] && (Input.GetMouseButtonDown(1) || !Input.GetKey(Tuner.KEYS_CHARACTER_ABILITY[i])) && HUDCast[i] == false) * { * if (!Input.GetKey(Tuner.KEYS_CHARACTER_ABILITY[i])) * { * unitCombat.castSpellInSlot(spellID); * } * targeting[i] = false; * shift = false; * } * } * else * { * if (Input.GetKeyDown(Tuner.KEYS_CHARACTER_ABILITY[i - 4]) && Input.GetKey(KeyCode.LeftShift) && unitCombat.isAlive()) * { * if (unitCombat.canCastSpell(spellID)) * { * targeting[i] = true; * shift = true; * } * } * if (targeting[i] && (Input.GetMouseButtonDown(1) || (!shift && !Input.GetKey(Tuner.KEYS_CHARACTER_ABILITY[i])) || (shift && !Input.GetKey(Tuner.KEYS_CHARACTER_ABILITY[i - 4]))) && HUDCast[i] == false) * { * if (!Input.GetKey(Tuner.KEYS_CHARACTER_ABILITY[i]) || (shift && !Input.GetKey(Tuner.KEYS_CHARACTER_ABILITY[i - 4]))) * { * unitCombat.castSpellInSlot(spellID); * } * targeting[i] = false; * shift = false; * } * } */ for (int i = 0; i < 8; i++) { int characterID = Mathf.FloorToInt((i * 0.5f) + 1); int abilityID = (i % 2); character = partySystem.getCharacter(characterID); Ability ability = character.GetComponent <UnitCombat>().getAbilityList()[abilityID]; if (targeting[i]) { targetedAbilityIndicator.showIndicator(character, ability, CameraScripts.getCurrentMousePos()); } else { targetedAbilityIndicator.hideIndicator(character, ability); } } if (isTargetingFromHUD() && !playerHUD.isMouseOverHUD()) { if (Input.GetMouseButtonDown(0)) { for (int i = 0; i < 8; i++) { setHUDCast(i, false); } } } }