Exemple #1
0
    void Update()
    {
        //is called when the player presses the left mouse button
        if (Input.GetMouseButtonDown(0))
        {
            //Finding the vector that is the middlepoint of the screen
            Vector3 point = new Vector3(_camera.pixelWidth / 2, _camera.pixelHeight / 2, 0);

            //Creates the ray on that point
            Ray ray = _camera.ScreenPointToRay(point);

            //Look for info on if the raycast hits anything
            RaycastHit hit;

            //What to do based on what the raycast hits
            if (Physics.Raycast(ray, out hit))
            {
                //if the raycast hits a GameObject with the ReactiveTarget script call ReactToHit()
                GameObject     hitObject = hit.transform.gameObject;
                ReactiveTarget target    = hitObject.GetComponent <ReactiveTarget>();

                if (target != null)
                {
                    target.ReactToHit();
                }
                else
                {
                    //If the raycast hits a object that is not a ReactiveTarget then run(SphereIndicator)
                    StartCoroutine(SphereIndicator(hit.point));
                }
            }
        }
    }
Exemple #2
0
 void Update()
 {
     if (Input.GetMouseButtonDown(0))
     {
         muzzleFlash.Play();
         mAudioSrc.Play();
         Vector3    point = new Vector3(_camera.pixelWidth / 2, _camera.pixelHeight / 2, 0);
         Ray        ray   = _camera.ScreenPointToRay(point);
         RaycastHit hit;
         if (Physics.Raycast(ray, out hit))
         {
             if (Physics.Raycast(ray, out hit))
             {
                 GameObject hitObjec = hit.transform.gameObject;
                 FinalBoss  targe    = hitObjec.GetComponent <FinalBoss>();
                 Instantiate(impactEffect, hit.point, Quaternion.LookRotation(hit.normal));
                 if (targe != null)
                 {
                     targe.ReactToHit(damage);
                 }
             }
         }
         if (Physics.Raycast(ray, out hit))
         {
             GameObject     hitObject = hit.transform.gameObject;
             ReactiveTarget target    = hitObject.GetComponent <ReactiveTarget>();
             Instantiate(impactEffect, hit.point, Quaternion.LookRotation(hit.normal));
             if (target != null)
             {
                 target.ReactToHit(damage);
             }
         }
     }
 }
    void Update()
    {
        if (Input.GetMouseButtonDown(0) && !EventSystem.current.IsPointerOverGameObject())
        {
            Vector3    point = new Vector3(_camera.pixelWidth / 2, _camera.pixelHeight / 2, 0);
            Ray        ray   = _camera.ScreenPointToRay(point);
            RaycastHit hit;
            if (Physics.Raycast(ray, out hit))
            {
                GameObject     hitObject = hit.transform.gameObject;
                ReactiveTarget target    = hitObject.GetComponent <ReactiveTarget>();
                if (target != null)
                {
                    target.ReactToHit();
                    soundSource.PlayOneShot(hitEnemySound);

                    /*soundSource.clip = hitEnemySound;
                     * soundSource.Play();*/
                    Messenger.Broadcast(GameEvent.ENEMY_HIT);
                }
                else
                {
                    StartCoroutine(SphereIndicator(hit.point));
                    soundSource.PlayOneShot(hitWallSound);

                    /*soundSource.clip = hitWallSound;
                     * soundSource.Play();*/
                }
            }
        }
    }
Exemple #4
0
    // Update is called once per frame
    void Update()
    {
        //on click
        if (Input.GetMouseButtonDown(leftBtn))
        {
            //create vector as point without length
            Vector3 point = new Vector3(_camera.pixelWidth / 2, _camera.pixelHeight / 2, 0);
            //create ray using vector
            Ray ray = _camera.ScreenPointToRay(point);
            //define hit data container
            RaycastHit hit;
            //check hit and save data to hit variable
            if (Physics.Raycast(ray, out hit))
            {
                //find shot target
                GameObject hitObject = hit.transform.gameObject;
                //find component of target
                ReactiveTarget target = hitObject.GetComponent <ReactiveTarget>();

                if (target != null)
                {
                    //if it was found - it was enemy
                    target.ReactToHit();
                }
                else
                {
                    //else hit wall with shpere and run iterator
                    StartCoroutine(SphereIndicator(hit.point));
                }
            }
        }
    }
Exemple #5
0
    // Start is called before the first frame update
    void Start()
    {
        GameObject hitObject = transform.gameObject;

        target    = hitObject.GetComponent <ReactiveTarget>();
        PlayerPos = GetComponent <Transform>();
    }
    void Update()
    {
        if (Input.GetMouseButtonDown(0) && !EventSystem.current.IsPointerOverGameObject())         //реакция на нажатие кнопки мыши
        {
            //середина экрана - это половина его высоты и ширины
            Vector3 point = new Vector3(_camera.pixelWidth / 2, _camera.pixelHeight / 2, 0);

            //создание в этой точке луча
            Ray ray = _camera.ScreenPointToRay(point);

            RaycastHit hit;
            if (Physics.Raycast(ray, out hit))
            {
                //получаем объект в который попал луч
                GameObject     hitObject = hit.transform.gameObject;
                ReactiveTarget target    = hitObject.GetComponent <ReactiveTarget>();
                if (target != null) //проверяем наличие у этого объекта компонента ReactiveTarget
                {
                    //вызов метода для мишени
                    target.ReactToHit();

                    Messenger.Broadcast(GameEvent.ENEMY_HIT); //кроме реакции на попадание - рассылаем сообщение
                }
                else
                {
                    //запуск корутина в ответ на попадание
                    StartCoroutine(SphereIndicator(hit.point));
                }
            }
        }
    }
Exemple #7
0
    // Update is called once per frame
    void Update()
    {
        if (Input.GetMouseButtonDown(0) && !EventSystem.current.IsPointerOverGameObject())
        {
            audioSource.PlayOneShot(shotSound);

            Vector3    point = new Vector3(_camera.pixelWidth / 2, _camera.pixelHeight / 2, 0.0f);
            Ray        ray   = _camera.ScreenPointToRay(point);
            RaycastHit hit;

            Debug.DrawRay(ray.origin, ray.direction);

            if (Physics.Raycast(ray, out hit))
            {
                //Debug.Log ("Hit " + hit.point);

                ;

                GameObject     hitObject = hit.transform.gameObject;
                ReactiveTarget target    = hitObject.GetComponent <ReactiveTarget> ();
                if (target != null)
                {
                    target.reactToHit();
                }
                else
                {
                    StartCoroutine(SphereIndicator(hit.point));
                }
            }
        }
    }
    // Update is called once per frame
    void Update()
    {
        // Triggered when LMB is clicked
        if (Input.GetMouseButtonDown(0))
        {
            // Center point of the screen is half the width and height
            Vector3 point = new Vector3(_camera.pixelWidth / 2, _camera.pixelHeight / 2, 0);
            // Create the ray at the position
            Ray ray = _camera.ScreenPointToRay(point);

            RaycastHit hit;                                                           // Data structure about the intersection of the ray; coordinate of the intersection and what object was intersected
            if (Physics.Raycast(ray, out hit))                                        // The raycast fills a referenced variable (hit) with information
            {
                GameObject     hitObject = hit.transform.gameObject;                  // Retrieve the object that the ray hit
                ReactiveTarget target    = hitObject.GetComponent <ReactiveTarget>(); // Get the ReactiveTarget component of the target object
                // Check if the ray hit an object with a ReactiveTarget component
                if (target != null)
                {
                    target.ReactToHit();
                }
                else
                {
                    StartCoroutine(SphereIndicator(hit.point)); // Coroutine to spawn a sphere at intersected ray location
                }
            }
        }
    }
Exemple #9
0
    // Update is called once per frame
    void Update()
    {
        if (Input.GetMouseButtonDown(0))
        {
            Vector3 point = new Vector3(_camera.pixelWidth / 2, _camera.pixelHeight / 2, 0);
            // The middle of the screen is half its width and height

            Ray ray = _camera.ScreenPointToRay(point);
            // Create the ray at the position using ScreenPointToRay()

            RaycastHit hit;
            if (Physics.Raycast(ray, out hit))
            {
                GameObject hitObject = hit.transform.gameObject;
                //retrieve the object the ray hit

                ReactiveTarget target = hitObject.GetComponent <ReactiveTarget>();

                if (target != null)
                {
                    target.ReactToHit();
                    //check for the ReactiveTarget component on the object
                    //Debug.Log("Target hit");
                }
                else
                {
                    StartCoroutine(SphereIndicator(hit.point));
                    // the Raycast fills a referenced variable with information
                }

                //Debug.Log("Hit " + hit.point);
                // Retrieve coordinates where the ray hit
            }
        }
    }
Exemple #10
0
    // Реакция на столкновение хамелеона с врагом
    private void OnTriggerEnter2D(Collider2D other)
    {
        ReactiveTarget player    = other.GetComponent <ReactiveTarget> ();
        Inventory      inventory = other.GetComponent <Inventory> ();

        // Если враг живой столкнулся а не мертвый упал сверху
        if (player != null && player._alive == true)
        {
            walk = false;
            ChameleonFall();
            // Шлем сообщение UIController-у о падении чтобы отнять одну жизнь в хамелеона
            Messenger.Broadcast(GameEvent.CHAMELEON_FALL);
        }
        if (inventory != null)
        {
            if (inventory._type == "BlinkClock(Clone)" && inventory._clockTaken == true)
            {
                Messenger <string> .Broadcast(GameEvent.RECEIVED_CLOCK_INV, "BlinkClock(Clone)");

                inventory._clockTaken = false;
            }
            if (inventory._type == "BlinkHeart(Clone)" && inventory._heartTaken == true)
            {
                Messenger <string> .Broadcast(GameEvent.RECEIVED_CLOCK_INV, "BlinkHeart(Clone)");
            }
            inventory._heartTaken = false;
        }
    }
Exemple #11
0
    void Update()
    {
        if (Input.GetMouseButtonDown(0))
        {
            Vector3    point = new Vector3(_camera.pixelWidth / 2, _camera.pixelHeight / 2, 0); //Wektor środka ekranu
            Ray        ray   = _camera.ScreenPointToRay(point);                                 //Generowanie promienia
            RaycastHit hit;                                                                     //Informacje o przecięciu z powierzchnią 3D

            //Raycast zbiera dane na temat punktu przeciecia
            if (Physics.Raycast(ray, out hit))
            {
                //Pobieranie informacji o trafionym obiekcie
                GameObject     hitObject = hit.transform.gameObject;
                ReactiveTarget target    = hitObject.GetComponent <ReactiveTarget>();

                //Jeśli zawiera skrypt o trafieniu, reaguj
                if (target != null)
                {
                    target.ReactToHit();
                }
                else
                {
                    //Podprocedura kul po strzale
                    StartCoroutine(SphereIndicator(hit.point));
                }
            }
        }
    }
    // Update is called once per frame
    void Update()
    {
        if (Input.GetMouseButtonDown(0))
        {
            Vector3    point = new Vector3(_camera.pixelWidth / 2, _camera.pixelHeight / 2, 0);
            Ray        ray   = _camera.ScreenPointToRay(point);
            RaycastHit hit;
            if (Physics.Raycast(ray, out hit))
            {
                GameObject hitObject = hit.transform.gameObject;

                // Grab script component
                ReactiveTarget target = hitObject.GetComponent <ReactiveTarget>();
                if (target != null)
                {
                    // Reactive Targets
                    target.ReactToHit();
                }
                else
                {
                    //  Non-Reactive - mark w/ a point
                    StartCoroutine(SphereIndicator(hit.point));
                }
            }
        }
    }
 // Update is called once per frame
 void Update()
 {
     // respond to the mouse button: 0 = left; 1 = right; 2 = middle
     if (Input.GetMouseButtonDown(0))
     {
         // the middle of the screen is half of its width and half of its height
         Vector3 point = new Vector3(_camera.pixelWidth / 2, _camera.pixelHeight / 2, 0);
         // create the ray at the center of the screen
         Ray        ray = _camera.ScreenPointToRay(point);
         RaycastHit hit;
         if (Physics.Raycast(ray, out hit))                       // raycast fills a reference variable with information
         {
             GameObject     hitObject = hit.transform.gameObject; // retrieve the object the ray hit
             ReactiveTarget target    = hitObject.GetComponent <ReactiveTarget>();
             if (target != null)                                  // make sure it is a reactive target
             {
                 Debug.Log("Target hit");
                 target.ReactToHit();
             }
             else
             {
                 StartCoroutine(SphereIndicator(hit.point)); // launch a coroutine in response to a hit
             }
         }
     }
 }
Exemple #14
0
    // Update is called once per frame
    void Update()
    {
        if (Input.GetMouseButtonDown(0))
        {
            Vector3    point = new Vector3(_camera.pixelWidth / 2, _camera.pixelHeight / 2, 0); // Center of screen is half the widith and half the height
            Ray        ray   = _camera.ScreenPointToRay(point);                                 // Create a ray
            RaycastHit hit;                                                                     // Used to store reference to the object that the ray may hit
            if (Physics.Raycast(ray, out hit))                                                  // Check if and get what the ray hit
            {
                Debug.Log("Hit " + hit.point);

                GameObject     hitObject = hit.transform.gameObject; // Retrieve the object the ray hit
                ReactiveTarget target    = hitObject.GetComponent <ReactiveTarget>();

                if (target != null) // If it is a enemy then do the enemy reaction function
                {
                    Debug.Log("Target Hit");
                    target.ReactToHit();
                }
                else                                            // else just show where you raycasted
                {
                    StartCoroutine(SphereIndicator(hit.point)); // call coroutine
                }
            }
        }
    }
Exemple #15
0
    // Update is called once per frame
    private void Update()
    {
        // IsPointerOverGameObject - проверяем что GUI не используется
        if (Input.GetMouseButtonDown((int)MouseButton.LeftMouse) && !EventSystem.current.IsPointerOverGameObject())
        {
            // получаем центр экрана
            Vector3 point = new Vector3(_camera.pixelWidth / 2, _camera.pixelHeight / 2, 0);

            // получаем луч проходящий из камеры через центр экрана
            Ray ray = _camera.ScreenPointToRay(point);

            RaycastHit hit;      // сбор информации о результатах выпускания луча

            if (Physics.Raycast(ray, out hit))
            {
                GameObject     hitObject = hit.transform.gameObject; // получаем объект в который попал луч
                ReactiveTarget target    = hitObject.GetComponent <ReactiveTarget>();

                if (target != null)
                {
                    target.ReactToHit();     // реакция цели, при попадании в нее
                    Messenger.Broadcast(GameEvent.ENEMY_HIT);
                }
                else
                {
                    StartCoroutine(SphereIndicator(hit.point));
                }
            }
        }
    }
    // Update is called once per frame
    void Update()
    {
        if (Input.GetMouseButtonDown(0))
        {
            Vector3    screenCenter = new Vector3(cam.pixelWidth / 2, cam.pixelHeight / 2, 0);
            Ray        ray          = cam.ScreenPointToRay(screenCenter);
            RaycastHit hit;
            Debug.DrawRay(ray.origin, ray.direction * 10, Color.yellow, 2); //indicators

            if (Physics.Raycast(ray, out hit))
            {
                Debug.Log(hit.point);
                GameObject     hitObject = hit.transform.gameObject;
                ReactiveTarget target    = hitObject.GetComponent <ReactiveTarget>();
                if (target != null)
                {
                    Debug.Log("target hit");
                    target.ReactToHit(); //call the react to hit function
                }
                else
                {
                    //Display a sphere  at hit point, then destroy the sphere
                    StartCoroutine(SphereIndicator(hit.point));
                }
            }
        }
    }
Exemple #17
0
    private void Update()
    {
        //Проверяем, когда нажимаем на "выстрел"
        if (Input.GetMouseButtonDown(0))
        {
            //Запоминаем центр экрана
            Vector3 screenСenter = new Vector3(Screen.width / 2, Screen.height / 2, 0);

            //Пускаем луч из центра экрана относительно камеры
            Ray        ray = _camera.ScreenPointToRay(screenСenter);
            RaycastHit hit;//улавливаем попадание в эту переменную

            //Если попали в какой то объект
            if (Physics.Raycast(ray, out hit))//пускаем луч ray результат столкновения считываем в hit
            {
                //Распознование попаданий в цель
                GameObject     hitObject = hit.transform.gameObject;                  //получаем объект, в который попали
                ReactiveTarget target    = hitObject.GetComponent <ReactiveTarget>(); //получаем компонет этого объекта

                //Проверим, попадание в мишень
                if (target != null)
                {
                    target.ReactToHit();
                }
                else
                {
                    //Запускаем сопрограмму
                    StartCoroutine(SphereInicatorCoroutine(hit.point));
                    //Рисуем отладочную линию, чтобы проследить траекторию луча
                    Debug.DrawLine(this.transform.position, hit.point, Color.green, 6);
                }
            }
        }
    }
Exemple #18
0
    // Update is called once per frame
    void Update()
    {
        if (Input.GetMouseButtonDown(0))
        {
            Vector3    point = new Vector3(_camera.pixelWidth / 2, _camera.pixelHeight / 2, 0); //metade da tela
            Ray        ray   = _camera.ScreenPointToRay(point);                                 //cria a linha que sai da câmera
            RaycastHit hit;                                                                     //variável para armazenar as coordenadas de onde foi atingido o objeto

            if (Physics.Raycast(ray, out hit))
            {
                GameObject     hitObject = hit.transform.gameObject;//retorna o objeto que foi atingidos
                ReactiveTarget target    = hitObject.GetComponent <ReactiveTarget>();

                if (target != null)
                {
                    target.ReactToHit();
                    print("Target hit");
                }
                else
                {
                    StartCoroutine(SphereIndicator(hit.point));
                }
            }
        }
    }
 /*void OnGUI()
  * {
  *  int size = 12;
  *  float posX = _camera.pixelWidth / 2 - size / 4;
  *  float posY = _camera.pixelHeight / 2 - size / 2;
  *  GUI.Label(new Rect(posX, posY, size, size), "+");
  * }*/
 // Update is called once per frame
 void Update()
 {
     if (Input.GetMouseButtonDown(0) && playerAmmo._ammo > 0)
     {
         playerAmmo._ammo -= 1;
         //Debug.Log("Player ammo: " + playerAmmo._ammo);
         Vector3    point = new Vector3(_camera.pixelWidth / 2, _camera.pixelHeight / 2, 0);
         Ray        ray   = _camera.ScreenPointToRay(point);
         RaycastHit hit;
         if (Physics.Raycast(ray, out hit))
         {
             GameObject     gameObject = hit.transform.gameObject;
             ReactiveTarget target     = gameObject.GetComponent <ReactiveTarget>();
             if (target != null)
             {
                 target.ReactToHit();
             }
             // Shows on enemy when its hit
             if (currentWeapon.selectedWeapon == 0)
             {
                 pistolShot.PlayOneShot(hiAction, 0.75f);
                 StartCoroutine(PistolIndicator(hit));
             }
             else
             {
                 akShot.PlayOneShot(impactor, 0.75f);
                 StartCoroutine(AkIndicator(hit));
             }
         }
     }
 }
Exemple #20
0
    void Update()
    {
        if (Input.GetMouseButtonDown(0))
        {
            // середина экрана
            Vector3 point = new Vector3(_camera.pixelWidth / 2, _camera.pixelHeight / 2, 0);
            // создаем программный объект Ray
            Ray ray = _camera.ScreenPointToRay(point);
            // создаем структуру данных, которая содержит в себе информацию о точке выходи и объекте столкновения луча
            RaycastHit hit;

            if (Physics.Raycast(ray, out hit))
            {
                GameObject     hitObject = hit.transform.gameObject;
                ReactiveTarget target    = hitObject.GetComponent <ReactiveTarget>();

                if (target != null)
                {
                    target.ReactToHit();
                }

                else

                {
                    StartCoroutine(SphereIndicator(hit.point));
                }
            }
        }
    }
Exemple #21
0
    // Update is called once per frame
    void Update()
    {
        if ((Input.GetMouseButtonDown(0)) &&      // по нажатию мыши
            !EventSystem.current.IsPointerOverGameObject())                                     // проверяем, что GIU не используется
        {
            Vector3    point = new Vector3(_camera.pixelWidth / 2, _camera.pixelHeight / 2, 0); // середина экрана
            Ray        ray   = _camera.ScreenPointToRay(point);                                 // создаем луч
            RaycastHit hit;                                                                     // информация о пересечении луча

            if (Physics.Raycast(ray, out hit))                                                  // испущенный луч заполняет информацией переменную, на которую имеется ссылка
            {
                GameObject     hitObject = hit.transform.gameObject;                            // объект в который попал луч
                ReactiveTarget target    = hitObject.GetComponent <ReactiveTarget>();
                if (target != null)
                {
                    //Debug.Log("Target hit");
                    target.ReactToHit();
                    Messenger.Broadcast(GameEvent.ENEMY_HIT);
                }
                else
                {
                    // выполняется при пересечении луча с препятствием
                    //Debug.Log("Hit " + hit.point);
                    StartCoroutine(SphereIndicator(hit.point));                     // StartCoroutine - запуск сопрограммы
                }
            }
        }
    }
Exemple #22
0
    // Update is called once per frame
    void Update()
    {
        if (Input.GetMouseButtonDown(0) && EventSystem.current.IsPointerOverGameObject() == false)    // Проверка - GUI не используется
        {
            Vector3 point = new Vector3(_camera.pixelWidth * 0.5f, _camera.pixelHeight * 0.5f, 0);

            Ray        ray = _camera.ScreenPointToRay(point);;
            RaycastHit hit;

            if (Physics.Raycast(ray, out hit))
            {
                GameObject     hitObject = hit.transform.gameObject; // Объект, в который попал луч
                ReactiveTarget target    = hitObject.GetComponent <ReactiveTarget>();

                if (target != null)
                {
                    target.ReactToHit();
                    Messenger.Broadcast(GameEvent.ENEMY_HIT);

                    soundSource.PlayOneShot(hitEnemySound); // Вызываем метод PlayOneShot() для воспроизведения звука
                }
                else
                {
                    StartCoroutine(SphereIndicator(hit.point));
                    soundSource.PlayOneShot(hitWallSound);
                }
            }
        }
    }
Exemple #23
0
    // Update is called once per frame
    void Update()
    {
        if (!buttonFreeze)
        {
            if (Input.GetMouseButtonDown(0))
            {
                Vector3    point = new Vector3(_camera.pixelWidth / 2, _camera.pixelHeight / 2, 0);
                Ray        ray   = _camera.ScreenPointToRay(point);
                RaycastHit hit;
                if (Physics.Raycast(ray, out hit))
                {
                    GameObject     hitObject = hit.transform.gameObject;
                    ReactiveTarget target    = hitObject.GetComponent <ReactiveTarget> ();

                    //is this object our Enemy?
                    if (target != null)
                    {
                        target.ReactToHit();
                    }
                    else
                    {
                        StartCoroutine(SphereIndicator(hit.point));
                    }
                }
            }
        }
    }
Exemple #24
0
    void Update()
    {
        if (Input.GetMouseButtonDown(0))
        {
            // Определяем точку центра экрана
            Vector3 point = new Vector3(_camera.pixelWidth / 2, _camera.scaledPixelHeight / 2, 0);
            // Создаем луч
            Ray        ray = _camera.ScreenPointToRay(point);
            RaycastHit hit;
            if (Physics.Raycast(ray, out hit))
            {
                // Определяем объект попадания луча
                GameObject     hitObject = hit.transform.gameObject;
                ReactiveTarget target    = hitObject.GetComponent <ReactiveTarget> ();
                Fireball       fireball  = hitObject.GetComponent <Fireball> ();

                // Проверяем попадание в цель
                if (target != null)
                {
                    target.ReactToHit();
                    //Debug.Log ("Target hit");
                }
                else if (fireball == null)
                {
                    StartCoroutine(SphereIndicator(hit.point));
                    //Debug.Log ("Hit " + hit.point);
                }
            }
        }
    }
Exemple #25
0
 // Update is called once per frame
 void Update()
 {
     //响应鼠标按键
     if (Input.GetMouseButtonDown(0) && !EventSystem.current.IsPointerOverGameObject())
     {
         Vector3    point = new Vector3(camera.pixelWidth / 2, camera.pixelHeight / 2, 0); //屏幕中心
         Ray        ray   = camera.ScreenPointToRay(point);                                //在摄像机所在位置创建射线
         RaycastHit hit;                                                                   //射线交叉信息的包装
         //Raycast给引用的变量填充信息
         if (Physics.Raycast(ray, out hit))                                                //out确保在函数内外是同一个变量
         {
             //hit.point:射线击中的坐标
             GameObject     hitObject = hit.transform.gameObject; //获取射中的对象
             ReactiveTarget target    = hitObject.GetComponent <ReactiveTarget>();
             if (target != null)                                  //检查对象上是否有ReactiveTarget组件
             {
                 target.ReactToHit();
                 Messenger.Broadcast(GameEvent.ENEMY_HIT);
             }
             else
             {
                 StartCoroutine(SphereIndicator(hit.point));//响应击中
             }
         }
     }
 }
Exemple #26
0
    // Update is called once per frame
    void Update()
    {
        if (Input.GetKeyDown(KeyCode.K))
        {
            Vector3 point = new Vector3(_camera.pixelWidth / 2, _camera.pixelHeight / 2);
            Ray     ray   = _camera.ScreenPointToRay(point);
            if (Physics.Raycast(ray, out var hit))
            {
                GameObject     hitObject = hit.transform.gameObject;
                ReactiveTarget target    = hitObject.GetComponent <ReactiveTarget>();
                if (target != null)
                {
                    target.ReactToHit(hit);
                }
                // else
                // {
                //     StartCoroutine(SphereIndicator(hit.point));
                // }
            }
        }

        if (Input.GetKey(KeyCode.Space))
        {
        }
    }
Exemple #27
0
    // Update is called once per frame
    void Update()
    {
        if (Input.GetMouseButtonDown(0))         //реакция на нажатие кнопки мыши
        {
            //середина экрана это половина его ширины и высоты
            Vector3 point = new Vector3(_camera.pixelWidth / 2, _camera.pixelHeight / 2, 0);
            //создание в этой точке луча
            Ray        ray = _camera.ScreenPointToRay(point);
            RaycastHit hit;                    //инфа о пересечении лучаб о точке где возник луч и об объекте с кот.столкнулся
            //испущенный луч заполняет информацией переменную, на которую имеется ссылка
            if (Physics.Raycast(ray, out hit)) //возвращает true если луч столкнулся
            {
                //Debug.Log("Hit " + hit.point); //загружаем коордтнаты точки, в которую попал луч

                GameObject     hitObject = hit.transform.gameObject;
                ReactiveTarget target    = hitObject.GetComponent <ReactiveTarget>();
                if (target != null)
                {
                    //Debug.Log("Target hit");
                    target.ReactToHit();
                }
                else
                {
                    StartCoroutine(SphereIndicator(hit.point));
                }
            }
        }
    }
 void Update()
 {
     if (Input.GetMouseButtonDown(0))
     {
         Vector3    point = new Vector3(_camera.pixelWidth / 2, _camera.pixelHeight / 2, 0);
         Ray        ray   = _camera.ScreenPointToRay(point);
         RaycastHit hit;
         if (Physics.Raycast(ray, out hit))
         {
             //获取击中的对象
             GameObject     hitObject = hit.transform.gameObject;
             ReactiveTarget target    = hitObject.GetComponent <ReactiveTarget>();
             // 判断是否包含ReactiveTarget组件,如果包含则说明该物体是个可击中的物体
             if (target != null)
             {
                 Debug.Log("target hit");
                 target.ReactToHit();  //调用该组件上的方法
             }
             else
             {
                 //运行协程来响应击中
                 StartCoroutine(SphereIndicator(hit.point));
             }
         }
     }
 }
Exemple #29
0
 // Update is called once per frame
 void Update()
 {
     if (Input.GetMouseButtonDown(0) &&
         !EventSystem.current.IsPointerOverGameObject())
     {
         Vector3    point = new Vector3(_camera.pixelWidth / 1.5f, _camera.pixelHeight / 1.5f, 0);
         Ray        ray   = _camera.ScreenPointToRay(point);
         RaycastHit hit;
         if (Physics.Raycast(ray, out hit))
         {
             /*
              * Technically, the hit information doesn’t return the game object hit;
              * it indicates the Transform component hit.
              * You can then access gameObject as a property of transform.
              */
             GameObject     hitObject = hit.transform.gameObject;
             ReactiveTarget target    = hitObject.GetComponent <ReactiveTarget>();
             if (target != null)
             {
                 target.ReactToHit();
                 soundSource.PlayOneShot(hitEnemySound);
                 Messenger.Broadcast(GameEvent.ENEMY_HIT);
             }
             else
             {
                 StartCoroutine(SphereIndicator(hit.point));
                 soundSource.PlayOneShot(hitWallSound);
             }
         }
     }
 }
 // Update is called once per frame
 void Update()
 {
     if (Input.GetMouseButtonDown(0) && !EventSystem.current.IsPointerOverGameObject() && !GlobalVariables.Paused)
     {
         Vector3    point = new Vector3(_camera.pixelWidth / 2, _camera.pixelHeight / 2, 0);
         Ray        ray   = _camera.ScreenPointToRay(point);
         RaycastHit hit;
         if (Physics.Raycast(ray, out hit))
         {
             Debug.Log("Hit " + hit.point);
             StartCoroutine(LineIndicator(hit.point, transform.position));
             GameObject     hitObject = hit.transform.gameObject;
             ReactiveTarget target    = hitObject.GetComponent <ReactiveTarget>();
             if (target != null)
             {
                 Debug.Log("Target Hit");
                 if (!target.dead)
                 {
                     StartCoroutine(HitIndicator());
                 }
                 target.ReactToHit();
                 Messenger.Broadcast(GameEvent.ENEMY_HIT);
             }
             else
             {
                 //StartCoroutine(SphereIndicator(hit.point));
             }
         }
     }
 }