Пример #1
0
 void OnTriggerEnter(Collider other)
 {
     if (other.tag == "Canoa")
     {
         Destroy(other.gameObject);
         source.PlayOneShot(coger);
         hud.AddScore(1);
     }
     if (other.tag.Equals("Respawn"))
     {
         hud.updateFood(200f);
         int num_sp = int.Parse(other.name.Substring(1));
         spf.StartCoroutine(spf.prova(num_sp - 1));
         source.PlayOneShot(comer);
         Destroy(other.gameObject);
     }
     if (other.tag.Equals("Barco"))
     {
         SceneManager.LoadScene("End");
     }
 }
Пример #2
0
    // Update is called once per frame
    void Update()
    {
        if (dead)
        {
            return;
        }

        if (m_health <= 0)
        {
            dead = true;
            m_hud.AddScore(m_addScore);
            m_animator.ResetTrigger("isWalking");
            m_animator.SetTrigger("isEnemyDead");
            Destroy(gameObject, 2.5f);
            Collider collider = GetComponent <Collider>();
            collider.enabled = false;

            m_navAgent.isStopped = true;
            return;
        }

        // NAV
        Vector3 currentPos = transform.position;

        currentPos.y = 0;
        Vector3 targetPos = m_nodes[m_targetNodeIndex].position;

        targetPos.y = 0;
        float distance = Vector3.SqrMagnitude(currentPos - targetPos);

        m_animator.SetTrigger("isWalking");

        // IF at target node
        if (distance <= 1.0f)
        {
            m_targetNodeIndex = 1 - m_targetNodeIndex;
            m_navAgent.SetDestination(m_nodes[m_targetNodeIndex].position);
        }
    }