Help please!!

Hello, For my game i want to make a script so when my character touches a crystal the crystal will disappear and it will add a number to a variable

I was wondering if anyone would help me out by giving me a script o look at and study or a tutorial on youtube or something like that. :slight_smile:

the variable will be called “crystalCount”
the character will be called “player”
the crystal that the player touches will be called “MagicalCrystal”

Many Thanks
MrBlading4ever

Resources section of this site. You can get a few turorials here.

you could try:

var crystalCount : int;

function OnCollisionEnter (collision : Collision) {
        
        if (collision.rigidbody.gameObject.name == "MagicCrystal") {
              crystalCount += 1;
              }
}

attach this to your player. I haven’t tested this but this should work :slight_smile:

add a destroy(this.collision.rigidbody.gameObject) in the loop will make the crystal disappear

Thanks for this i havent tried yet because im on a different computer but is this java script yea?

Yeah its JavaScript, im not too good with C#