> For the complete documentation index, see [llms.txt](https://maxim218.gitbook.io/unity/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://maxim218.gitbook.io/unity/ubiistvo-monstra.md).

# Убийство монстра

Данный скрипт навешивается на монстра.

Скрипт содержит метод **monsterKill**, который в начале поворачивает монстра на определённый угол, после чего подключает скрипт **"ccc"**, который удаляет монстра через определённое время.

```
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class eee : MonoBehaviour {

    void Start () {
        // пусто
    }

    void Update () {
        // пусто
    }

    public void monsterKill()
    {
        // поворачиваем объект
        transform.Rotate(-125, 0, 0);
        // добавляем скрипт, отвечающий за удаление чере 5 сек
        gameObject.AddComponent<ccc>();
    }
}
```

Скрипт для стрельбы.

```
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class bbb : MonoBehaviour
{
    public Camera camera = null;

    void Start()
    {
        // пусто
    }

    void Update()
    {
        // при щелчке мышкой
        if (Input.GetMouseButtonDown(0))
        {
            float middleW = camera.pixelWidth / 2;
            float middleH = camera.pixelHeight / 2;
            Vector3 point = new Vector3(middleW, middleH, 0);
            Ray ray = camera.ScreenPointToRay(point);
            RaycastHit hit;
            if (Physics.Raycast(ray, out hit))
            {
                // получаем объект, по которому попали
                GameObject hitObj = hit.transform.gameObject;
                // получаем компонент (скрипт) объетка
                // имя компонента должно быть "eee"
                eee s = hitObj.GetComponent<eee>();
                // если такой компонент есть у объекта
                if(s != null)
                {
                    // вызываем метод компонента
                    s.monsterKill();
                }
                else
                {
                    Debug.Log("IT IS NOT MONSTER");
                }
            }
        }
    }
}
```
