# Shield
*The gun's sprite is sourced*
- There is an unarmed player and an armed enemy. When the player enters their range, the enemy fires at the player.
- When the player picks up the shield, it is held in front of the player (becomes a child object).
- The shield has three hit points. It is destroyed after taking three hits.
![[DESIGNS/TOYS/Shield.gif]]
### Enemy Controller
```cs
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class EnemyControllerParCh_HL1 : MonoBehaviour
{
public GameObject bsp; // bullet spawn point
public GameObject bullet;
private GameObject bulletClone;
private void OnTriggerEnter2D(Collider2D collision)
{
if (collision.gameObject.CompareTag("Player"))
{
InvokeRepeating("Shoot", 0, 2f);
}
}
private void OnTriggerExit2D(Collider2D collision)
{
if (collision.gameObject.CompareTag("Player"))
{
CancelInvoke("Shoot");
}
}
private void Shoot()
{
bulletClone = Instantiate(bullet, new Vector3 (10, -5.35f, 0), Quaternion.Euler(0, 0, 0));
bulletClone.GetComponent<Rigidbody2D>().velocity = new Vector3(-20, 0, 0);
Destroy(bulletClone, 5);
}
}
```
### ShieldController
```cs
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Shield_PCh_HL1 : MonoBehaviour
{
private int hitsCounter = 0;
private void OnCollisionEnter2D(Collision2D col)
{
if (col.gameObject.CompareTag("Player"))
{
gameObject.transform.parent = col.gameObject.transform;
gameObject.transform.rotation = Quaternion.Euler(0, 0, 0);
gameObject.transform.position = new Vector3(gameObject.transform.position.x, -4.8f, 0);
}
if (col.gameObject.CompareTag("Bullet"))
{
hitsCounter++;
Destroy(col.gameObject);
CheckHitsCounter();
}
}
private void CheckHitsCounter()
{
if (hitsCounter >= 3)
{
Destroy(gameObject);
}
}
}
```
+Avatar Controller (basic)
![[IBU/APPENDIX/(_IB_)/borders.(_IB_)|borders.(_IB_)]]