private GameObject CheckClickInput()   // sending clicking and hovering messages
    // I'm assuing there's only one object in contact with player
    {
        RaycastHit hit;
        bool       isClicking = Input.GetMouseButton(0);

        if (Physics.Raycast(myCamera.transform.position, myCamera.transform.forward, out hit, Mathf.Infinity, runeLayer))
        {
            // if it's in "touching range"
            if (hit.distance <= interactRange)
            {
                Clickable hovered = hit.collider.gameObject.GetComponent <Clickable>();
                if (isClicking)
                {
                    hovered.Click();
                }
                else
                {
                    hovered.Hover();
                }

                return(hit.collider.gameObject);
            }
        }
        else
        {
            Debug.Log("no hit");
        }

        return(null);
    }
Exemple #2
0
    void Update()
    {
        if (active)
        {
            if (nextSpawnIncrease < Time.time)
            {
                nextSpawnIncrease = Time.time + spawnIncreaseRate;
                spawnRate        *= 1.01f;
            }
            if (Random.value < spawnRate)
            {
                spaceRocks.Add(Instantiate(comet, new Vector3(Random.value - 0.5f, Random.value - 0.5f, 0).normalized * 10f, Quaternion.identity));
            }
            if (Random.value < spawnRate)
            {
                spaceRocks.Add(Instantiate(asteroid, new Vector3(Random.value - 0.5f, Random.value - 0.5f, 0).normalized * 10f, Quaternion.identity));
            }
        }
        RaycastHit hit;
        Ray        ray = camera.ScreenPointToRay(Input.mousePosition);

        if (Physics.Raycast(ray, out hit))
        {
            if (Input.GetMouseButton(0))
            {
                Planet p = hit.transform.GetComponent <Planet>();
                if (p)
                {
                    p.Hold();
                }
            }
            if (Input.GetMouseButtonDown(0))
            {
                Planet p = hit.transform.GetComponent <Planet>();
                if (p)
                {
                    p.Click();
                    return;
                }
                SpaceRock sr = hit.transform.GetComponent <SpaceRock>();
                if (sr)
                {
                    sr.Click();
                    return;
                }
                Clickable c = hit.transform.GetComponent <Clickable>();
                if (c)
                {
                    c.Click();
                    return;
                }
            }
            else
            {
                Clickable c = hit.transform.GetComponent <Clickable>();
                if (c)
                {
                    c.Hover();
                    return;
                }
            }
        }
        if (Input.GetKeyDown(KeyCode.DownArrow))
        {
            LowerHeat();
        }
        if (Input.GetKeyDown(KeyCode.UpArrow))
        {
            RaiseHeat();
        }
    }