Changing a variable from another script.

So I have a couple of scripts and have no errors… But what I need to happen isn’t.
My first script is to throw rocks, this only happens when the variable myrocks is greater than 0.

var speed = 3.0;
var rockprefab:Transform;
var myrocks = 0;


function Update () 
{
     if(Input.GetButtonDown("Fire1")  myrocks > 0)
     {
         myrocks --;
         
         var rock = Instantiate(rockprefab, transform.position, Quaternion.identity);
         
         rock.rigidbody.AddForce(transform.forward * 2000);
     }
}

So I need to have rocks to pick up and add to that variable, I’ve done this with a trigger and the script looks like this…

var RockScriptOBJ : GameObject;


function OnTriggerStay () {   
 
        if(collider.gameObject.CompareTag("Player")){
        
           if(Input.GetButtonDown("E"))
           {
              RockScriptOBJ.GetComponent.< shoot >().myrocks = 5;
           }
        
        }
}

Looking through other question I believe this is how you call variables from different scripts (correct me if I’m wrong) but it isn’t changing it. I’ve set the capsule to player and even tried to put a debug message in it but nothing came up. Can anyone tell me where I’m going wrong? Would be much appreciated! Thanks.

Where is your RockScriptOBJ script attached to? It seems like you’re checking if the object that your RockScriptOBJ script is attached to is tagged as player. I think you would want to do it when the player has entered the trigger? If so then you’ll need an argument in your OnTriggerStay (jn fact, you should have an argument in there)

Compare the tag of that argument to check if it’s the player and see if it works. If it doesn’t, check if either the player or the object that the RockScriptOBJ script is attached to has a rigidbody. Also check if the object with the RockScriptOBJ script has the isTrigger checked in its collider.

The script is on my game camera. It’s all working now I changed it to

Thanks for your help! Now I just need to destroy the game object so you can only take from it once, and add a GUI to show that you can pick up something.