private void HandleBulletVsTankCollision(Tank tank, Bullet bullet) { if (bullet.TeamIndex != tank.TeamIndex) { tank.ApplyDamage(bullet.Damage); bullet.Destroy(); } }
void OnTriggerEnter2D(Collider2D other) { Tank hitTank = other.GetComponent <Tank> (); if (hitTank != null && hitTank != owner) { hitTank.ApplyDamage(damage); Destroy(gameObject); } }
void Update() { var direction = Vector3.zero; if (Input.GetKey(KeyCode.W)) { direction += Vector3.up; } if (Input.GetKey(KeyCode.A)) { direction -= Vector3.right; } if (Input.GetKey(KeyCode.S)) { direction -= Vector3.up; } if (Input.GetKey(KeyCode.D)) { direction += Vector3.right; } direction.Normalize(); var moveForward = Vector3.Dot(direction, transform.up) > 0; if (direction.magnitude > Mathf.Epsilon) { tank.TurnToward(direction); if (moveForward) { tank.MoveForward(); } else { tank.MoveBackward(); } } var mousePos = camera.ScreenToWorldPoint(Input.mousePosition); mousePos.z = 0; tank.cannon.AimToward((mousePos - transform.position).normalized); if (Input.GetMouseButtonDown(0)) { tank.cannon.Fire(); } if (Input.GetKeyDown(KeyCode.R)) { tank.ApplyDamage(100); } }
void OnTriggerEnter(Collider other) { Debug.Log("Blowing up shell"); // Check if it hit a tank Tank tank = other.gameObject.GetComponentInParent <Tank>(); // Have to grab script from parent since colliders are on child objects if (tank != null) { tank.ApplyDamage(20); } Explode(); }