예제 #1
0
    // Update is called once per frame
    void Update()
    {
        if (Input.GetMouseButtonDown(0))
        {
            VisualEffect.Play();
            audioInstance.PlayRandomFromTag("spray");
        }

        Debug.DrawRay(transform.position, transform.up, Color.green);
        RaycastHit hit;

        if (Physics.Raycast(transform.position, transform.up, out hit, 100))
        {
            MoldContainer mold = hit.collider.gameObject.GetComponent <MoldContainer>();

            if (mold != null && Input.GetMouseButtonDown(0)) //&& mold != moldInFocus
            {
                SetFocus(mold);
            }
            else if (mold == null)
            {
                RemoveFocus();
            }
        }

        void SetFocus(MoldContainer newFocus)
        {
            //if (newFocus != moldInFocus)
            //{
            if (moldInFocus != null)
            {
                moldInFocus.OnDefocus();
            }

            moldInFocus = newFocus;
            moldInFocus.OnFocus();
            //}
        }

        void RemoveFocus()
        {
            if (moldInFocus != null)
            {
                moldInFocus.OnDefocus();
            }
            moldInFocus = null;
        }
    }
예제 #2
0
    // Update is called once per frame
    void Update()
    {
        timer += Time.deltaTime;

        _lookAt.SetGazeTypeReset(LookAt.LookTypes.followGaze);

        Debug.DrawRay(transform.position, transform.forward, Color.green);
        RaycastHit hit;

        if (Physics.Raycast(transform.position, transform.forward, out hit, 100))
        {
            MoldContainer mold = hit.collider.gameObject.GetComponent <MoldContainer>();

            if (mold != null)
            {
                if (!runOnce)
                {
                    light.color = Color.red;
                    _LightLookingAtMold.Invoke();
                    _audioManager.FadeSoundIn("HouseCreak", 1);
                    StartCoroutine(_cameraShake.StartShake(cameraShakeMagnitude));
                    runOnce = true;
                }
                currentMoldFocus = mold;
                currentMoldFocus.SetLightFocus(true);
                if (timer > regenTimer)
                {
                    mold.RegenHealth(20);
                    timer = 0;
                }
            }
            else if (mold == null && currentMoldFocus != null)
            {
                if (runOnce)
                {
                    LightStoppedLookingAtMold.Invoke();
                    _audioManager.FadeSoundOut("HouseCreak", 2);
                    StartCoroutine(_cameraShake.StopShake(cameraShakeMagnitude));
                    runOnce = false;
                }
                currentMoldFocus.SetLightFocus(false);
                light.color = Color.white;
                timer       = 0;
            }
        }
    }