public void OnDeathEvent() { GameObject parent = gameObject; CombatAttackModel combatAttackModel = GetComponent("CombatAttackModel") as CombatAttackModel; if (combatAttackModel) { parent = combatAttackModel.Owner; } CombatGod.SpawnCombatActor(DeathAttack, this.transform.position, parent, combatAttackModel); }
public void Collide(Collider collider) { // Collide when active. if (mCombatAttackModel.IsActive) { // Only collide with CombatReceivers that are active. CombatReceiverModel receiverModel = collider.gameObject.GetComponent("CombatReceiverModel") as CombatReceiverModel; if (receiverModel != null && receiverModel.IsActive) { // Check masks to see if these should interact. if (mCombatAttackModel.CollisionMask == receiverModel.CollisionMask) { // An attack collision has occured, resolve it. CombatGod.ResolveAttackCollision(mCombatAttackModel, receiverModel); } } } }
// Update is called once per frame void Update() { if (Input.GetButtonDown("Fire1")) { // Construct a ray from the current mouse coordinates Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); if (Physics.Raycast(ray)) { // Determine direction of bullet flight. Vector3 worldPointFromScreenPoint = Camera.mainCamera.ScreenToWorldPoint( new Vector3(Input.mousePosition.x, Input.mousePosition.y, Camera.mainCamera.nearClipPlane)); Vector3 direction = new Vector3(worldPointFromScreenPoint.x, 0, worldPointFromScreenPoint.z); float damage = GetHealthCostPerShot(); mCombatReceiverModel.AlterHealthPoints(-damage); GameObject bulletGO = CombatGod.SpawnBullet(Bullet, gameObject, new Vector3(), direction); bulletGO.renderer.material.color = gameObject.renderer.material.color; } } if (Input.GetButtonDown("Fire2")) { GameObject shield = Instantiate(Shield) as GameObject; //ActorModel shieldModel = shield.GetComponent("ActorModel") as ActorModel; //shieldModel.ParentActor = GetComponent("ActorModel") as ActorModel; // ignore the dude //Physics.IgnoreLayerCollision(shield.layer, gameObject.layer); //... and his bullets //Physics.IgnoreLayerCollision(shield.layer, BulletLayer); //if (shieldModel == null) //{ // throw new MissingComponentException("ActorModel not found on shield"); //} //shield.transform.position += transform.position; } }