how to make one script change a variable in another scipt

I want this script to change a variable in another script. The variable is called boxamount, in the script called Placegadget. this is what i have tried, but it won’t worke.

using UnityEngine;
using System.Collections;

public class Pickupgadget : MonoBehaviour {

void Update () {
	if (Input.GetKeyDown(KeyCode.E))
		Placegadget placegadget = GetComponent<Placegadget>();
Vector3 fwd = transform.TransformDirection(Vector3.forward);
		RaycastHit hit;
			if (Physics.Raycast(transform.position, fwd, out hit, 1.5f))
			 Debug.DrawRay(transform.position, fwd,;


I don’t see where is the variable you’re trying to change, so I’ll stay generic :

To access a variable of an object, you an instance and the right to access it (=> public/protected/private, to keep it simple). Make sure your boxamount is public.

Also, I see your accessing the component Placegadget from the same object, to SendAMessage. You don’t need to do that to a function from it. It wored, but you didn’t take the shortest way (Get the component, get it’s transform, send a message to every components of that object, the first component pick it up, execute) when you just need to call SendMessage from the script you wrote.

Here is an example how:

var objectWithTheScript : GameObject;
var theScript;

function Start() {
    theScript = objectWithTheScript.GetComponent("The Scripts Name");

function Update() {
    theScript.variableInTheScript = (whatever);

Now you can get much more complicated with that but that’s it really!