> 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/strelba-sferami.md).

# Стрельба сферами

```
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 s = GameObject.CreatePrimitive(PrimitiveType.Sphere);
                // задание положения сферы
                s.transform.position = hit.point;
            }
        }
    }
}
```
