Ejemplo n.º 1
0
    // Start is called before the first frame update
    void Start()
    {
        // Gets number of enemies text script
        _enemyTextScript = FindObjectOfType <EnemyTextScript>();

        // Gets components
        _edible  = GetComponent <Edible>();
        _harmful = GetComponent <Harmful>();

        // Sets up events
        _edible.CaughtEvent = () =>
        {
            // Destroy horizontal movement
            Destroy(GetComponent <HorizontalMovement>());

            // Stops us from being harmful
            _harmful.enabled = false;

            // Deduct enemy count
            if (_enemyTextScript != null)
            {
                _enemyTextScript.DeductCount();
            }

            // Disables exploder, if we have one
            Exploder exploder = GetComponent <Exploder>();
            if (exploder != null)
            {
                exploder.enabled = false;
            }
        };
        _edible.EatenEvent = () => { };
    }
Ejemplo n.º 2
0
    public void OnCollisionEnter(Collision c)
    {
        Harmful h = c.transform.GetComponent <Harmful>();

        if (h != null)
        {
            Life -= h.Damages;
        }
    }
Ejemplo n.º 3
0
    //dont override
    private void OnCollisionEnter(Collision collision)
    {
        //stop checking if collision cant be harmful
        Harmful hurt = collision.gameObject.GetComponent <Harmful>();

        if (hurt == null)
        {
            return;
        }

        //don't get damaged if it cant hurt you
        if (invulnerableTo.Contains(hurt))
        {
            return;
        }

        //account for recent damage
        damaged      = true;
        secondsSince = 0;

        damage(hurt.getHarm());
    }