void OnCollisionEnter2D(Collision2D other)
    {
        Ruby_PlayerCharacter_Script player = other.gameObject.GetComponent <Ruby_PlayerCharacter_Script>();

        if (player != null)
        {
            player.ChangeHealth(-2);
        }
    }
    void OnTriggerStay2D(Collider2D other)
    {
        Ruby_PlayerCharacter_Script controller = other.GetComponent <Ruby_PlayerCharacter_Script>();

        if (controller != null)
        {
            controller.ChangeHealth(-1);
        }
    }
Example #3
0
    void OnTriggerEnter2D(Collider2D other)
    {
        Ruby_PlayerCharacter_Script controller = other.GetComponent <Ruby_PlayerCharacter_Script>();

        if (controller != null)
        {
            if (controller.health < controller.maxHealth)
            {
                controller.ChangeHealth(1);
                Destroy(gameObject);

                controller.PlaySound(collectedClip);
            }
        }
    }
    // Start is called before the first frame update
    void Start()
    {
        rigidbody2D = GetComponent <Rigidbody2D>();
        timer       = changeTime;
        animator    = GetComponent <Animator>();

        GameObject rubyControllerObject = GameObject.FindWithTag("RubyController"); //this line of code finds the RubyController script by looking for a "RubyController" tag on Ruby

        if (rubyControllerObject != null)
        {
            rubyController = rubyControllerObject.GetComponent <Ruby_PlayerCharacter_Script>(); //and this line of code finds the rubyController and then stores it in a variable

            print("Found the RubyController Script!");
        }

        if (rubyController == null)

        {
            print("Cannot find GameController Script!");
        }
    }