Загрузка...

Ругается Unity, помогити

Тема в разделе C# создана пользователем Аникс 1 авг 2024. 130 просмотров

Загрузка...
  1. Аникс
    Аникс Автор темы 1 авг 2024 0 22 янв 2021
    Пишет ошибку Assets\Scripts\Selection.cs(6,14): error CS0101: The namespace '<global namespace>' already contains a definition for 'SelectController'

    Вот код, что тут не так
    using System;
    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;

    public class SelectController : MonoBehaviour
    {

    public GameObject cube;
    public List<GameObject> players;
    public LayerMask layer, LayerMask;
    private Camera _cam;
    private GameObject _cubeSelection;
    private RaycastHit _hit;

    private void Awake() {
    _cam = GetComponent<Camera>();
    }

    private void Update()
    {
    if (Input.GetMouseButtonDown(1) && players.Count > 0)
    {
    Ray ray = _cam.ScreenPointToRay(Input.mousePosition);

    if (Physics.Raycast(ray, out RaycastHit _agentTarget, 1000f, layer))
    foreach(var el in players)
    el.GetComponent<UnityEngine.AI.NavMeshAgent>().SetDestination(_agentTarget.point);
    }

    if (Input.GetMouseButtonDown(0))
    {
    foreach (var el in players)
    el.transform.GetChild(0).gameObject.SetActive(false);

    players.Clear();

    Ray ray = _cam.ScreenPointToRay(Input.mousePosition);

    if (Physics.Raycast(ray, out _hit, 1000f, layer))
    _cubeSelection = Instantiate(cube, new Vector3(_hit.point.x , 1, _hit.point.z), Quaternion.identity);


    }



    if(_cubeSelection)
    {
    Ray ray = _cam.ScreenPointToRay(Input.mousePosition);

    if (Physics.Raycast(ray, out RaycastHit hitDrag, 1000f, layer))
    {

    float xScale = (_hit.point.x - hitDrag.point.x);
    float zScale = _hit.point.z - hitDrag.point.z;

    if(xScale < 0.0f && zScale < 0.0f)
    _cubeSelection.transform.localRotation = Quaternion.Euler(new Vector3(0, 180, 0));
    else if(xScale < 0.0f )
    _cubeSelection.transform.localRotation = Quaternion.Euler(new Vector3(0, 0, 180));
    else if(zScale < 0.0f)
    _cubeSelection.transform.localRotation = Quaternion.Euler(new Vector3(180, 0, 0));
    else
    _cubeSelection.transform.localRotation = Quaternion.Euler(new Vector3(0, 0, 0));


    _cubeSelection.transform.localScale = new Vector3(Mathf.Abs(xScale), 1,Mathf.Abs(zScale));
    }
    }

    if (Input.GetMouseButtonUp(0) && _cubeSelection)
    {
    RaycastHit[] hits = Physics.BoxCastAll(
    _cubeSelection.transform.position,
    _cubeSelection.transform.localScale,
    Vector3.up,
    Quaternion.identity,
    0,
    LayerMask
    );

    foreach (var el in hits)
    {
    players.Add(el.transform.gameObject);
    el.transform.GetChild(0).gameObject.SetActive(true);
    }

    Destroy(_cubeSelection);
    }

    }


    }
     
    1. CLS
      Аникс, Название класса SelectController поменяй, либо заверни в namespace свой
Top