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.