public void Attack(AttackingObject attackingObject) { switch (attackingObject.type) { case AttackTypes.PistolShot: t = attackingObject.transform; GameObject.Instantiate(pistolShotEffect, t.position, t.rotation); RaycastHit hit; if (Physics.Raycast(attackingObject.transform.position, attackingObject.transform.forward, out hit, attackingObject.range)) { Debug.DrawRay(transform.position, transform.TransformDirection(Vector3.forward) * hit.distance, Color.yellow); if (hit.collider.gameObject.CompareTag("Damagable")) { hit.collider.GetComponent <DamagableObject>().RemoveHP(attackingObject.damage); } } break; default: Debug.LogError("Undefined attack"); break; } }
void Start() { parent = transform.parent; attackingObject = parent.GetComponent <AttackingObject>(); if (attackingObject == null) { parent = parent.parent; attackingObject = parent.GetComponent <AttackingObject>(); } }
void Start() { parent = transform.parent; parentComponent = parent.GetComponent <AttackingObject>(); if (parentComponent == null) { parent = parent.parent; parentComponent = parent.GetComponent <AttackingObject>(); } spellUnits = parentComponent.spellUnits; }
void Start() { parent = transform.parent; attackingObject = parent.GetComponent <AttackingObject>(); if (attackingObject == null) { parent = parent.parent; attackingObject = parent.GetComponent <AttackingObject>(); } meleeUnits = attackingObject.meleeUnits; rangeUnits = attackingObject.rangeUnits; }
public void Attack(AttackingObject attackingObject) { switch (attackingObject.type) { case AttackTypes.PistolShot: t = attackingObject.transform; if (PhotonNetwork.IsConnected) { PhotonNetwork.Instantiate(pistolShotEffect.name, t.position, t.rotation); } else { GameObject.Instantiate(pistolShotEffect, t.position, t.rotation); } RaycastHit hit; if (Physics.Raycast(attackingObject.transform.position, attackingObject.transform.forward, out hit, attackingObject.range)) { Debug.DrawRay(transform.position, transform.TransformDirection(Vector3.forward) * hit.distance, Color.yellow); if (hit.collider.gameObject.CompareTag("Damagable")) { hit.collider.GetComponent <DamagableObject>().RemoveHP(attackingObject.damage); } } break; case AttackTypes.BazookaShot: t = attackingObject.transform; if (PhotonNetwork.IsConnected) { prefab = PhotonNetwork.Instantiate(bazookaShotEffect.name, t.position, t.rotation); } else { prefab = GameObject.Instantiate(bazookaShotEffect, t.position, t.rotation); } prefab.GetComponent <Rigidbody>().velocity = t.forward * attackingObject.speed; break; case AttackTypes.SwordSwing: t = attackingObject.transform; if (PhotonNetwork.IsConnected) { PhotonNetwork.Instantiate(swordSwingEffect.name, t.position, t.rotation); } else { GameObject.Instantiate(swordSwingEffect, t.position, t.rotation); } break; default: Debug.LogError("Undefined attack"); break; } }