0
\$\begingroup\$

The idea is to access the function BlockWasDestroyed(); from Combo class.

Instead of var combo = gameObject.GetComponent(Combo); I've also tried with

var combo = GetComponent(Combo);

var combo:Combo = gameObject.GetComponent(Combo);

var combo:Combo = GetComponent(Combo);

But the console keeps telling it's null. However it could work when the function was static, but thing is now that function is calling another function, and so the errors happen once again.

Here's my code so far:

Brick.js

#pragma strict

public class Brick extends MonoBehaviour{
    
    function OnCollisionEnter(col : Collision){
        if(col.gameObject.name == "Ball"){
            var ballb = gameObject.GetComponent(BouncingBall);
            var combo = gameObject.GetComponent(Combo);
            combo.BlockWasDestroyed();
            ballb.velocityZ = ballb.velocityZ * -1;
            Score.score += 20;
            Destroy(this.gameObject);
        }
    }
}
\$\endgroup\$
2
\$\begingroup\$

There is no Combo attached to the GameObject to which Brick is attached, most likely.

Are you sure you don't mean this?

#pragma strict

public class Brick extends MonoBehaviour{

    function OnCollisionEnter(col : Collision){
        if(col.gameObject.name == "Ball") {
            var ballObj = col.gameObject;
            var ballb = ballObj.GetComponent(BouncingBall); //Getting components 
                                                            //from the ball instead.
            var combo = ballObj.GetComponent(Combo);
            combo.BlockWasDestroyed();
            ballb.velocityZ = ballb.velocityZ * -1;
            Score.score += 20;
            Destroy(this.gameObject);
        }
    }
}
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.