Beispiel #1
0
    // Update is called once per frame
    void Update()
    {
        if (!penguin)
        {
            penguin = GameSession.current.penguin;
            return;
        }

        transform.position = transform.parent.position;

        if (GameSession.current.penguinBusy && !interacting)
        {
            return;
        }

        if (!interacting)
        {
            if (Vector3.Distance(transform.position, penguin.transform.position) <= max_distance && GameSession.current.penguinTracked && GameSession.current.sealTracked)
            {
                StopAllCoroutines();
                happinessIncreaseSpeed = Mathf.Max(happinessIncreaseSpeed, 1.5f * GameSession.current.happinessDecayingSpeed);
                StartCoroutine(PerformHappiness());
                GameSession.current.penguinBusy = true;
                interacting = true;
            }
        }
        else
        {
            if (Vector3.Distance(transform.position, penguin.transform.position) > max_distance || !GameSession.current.penguinTracked || !GameSession.current.sealTracked)
            {
                StopAllCoroutines();
                StartCoroutine(ReturnToPlace());
                GameSession.current.penguinBusy = false;
                interacting = false;
            }
        }
    }
    // Update is called once per frame
    void Update()
    {
        if (washToggle.isOn)
        {
            if (Input.touchCount > 0 || Input.GetMouseButton(0))
            {
                RaycastHit hit;
                if (RaycastProvider.GetRaycastHit(touchablesLayer, out hit))
                {
                    if (hit.collider.GetComponentInParent <PenguinBehavior>() == penguin)
                    {
                        _cleaningObject.transform.GetComponentInChildren <ParticleSystem>(true).gameObject.SetActive(true);
                        penguin.higiene         += Time.deltaTime * higieneIncreaseSpeed;
                        _cleaningObject.position = hit.point;
                        _cleaningObject.forward  = hit.normal;

                        penguin.audioSource.UnPause();
                        if (!penguin.audioSource.isPlaying)
                        {
                            penguin.audioSource.PlayOneShot(penguin.washAudioClip);
                        }
                    }
                }
            }
            else
            {
                _cleaningObject.transform.GetComponentInChildren <ParticleSystem>(true).gameObject.SetActive(false);
                penguin.audioSource.Pause();
            }
        }

        if ((Input.touchCount > 0 || Input.GetMouseButtonUp(0)) && !penguinBusy)
        {
            Transform touchedGOTransform = RaycastProvider.GetRaycastedTouchable(touchablesLayer.value);
            if (touchedGOTransform)
            {
                if (touchedGOTransform.GetComponentInParent <Fish>())
                {
                    touchedGOTransform.GetComponentInParent <Fish>().Grab();
                }
                else
                {
                    touchedGOTransform.GetComponentInParent <Animator>().SetTrigger("touch");

                    if (!penguin)
                    {
                        penguin = touchedGOTransform.GetComponent <PenguinBehavior>();   // if there is no such component, null will be set
                        if (penguin)
                        {
                            penguin.initialize(initialHunger, initialHappiness, initialHigiene);
                            washToggle.gameObject.SetActive(true);
                        }
                    }
                    else
                    {
                        penguin.audioSource.PlayOneShot(touchedGOTransform.GetComponent <PenguinBehavior>() ? penguin.greetingAudioClip : penguin.sealAudioClip);
                    }
                }
            }
        }

        if (penguin)
        {
            penguin.updateState();
        }
    }
 private void Start()
 {
     penguin = transform.parent.GetComponent <PenguinBehavior>();
     _invisibleDirectionPlane = Instantiate(invisibleDirectionPlane, transform);
     _invisibleDirectionPlane.gameObject.SetActive(false);
 }