Beispiel #1
0
    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;
                WanderingAI target    = hitObject.GetComponent <WanderingAI>();

                if (target != null)
                {
                    target.ReactToHit();
                    Debug.Log("target hit!");
                }
                else
                {
                    StartCoroutine(SphereIndicator(hit.point));
                }
            }
        }
    }