Send value to another script

Hello. I am trying to change a value in another script. I have a GUITexture called gasbutton. This is that GUITextures’s code.

public var motorInput;

function Start () {
motorInput = GetComponent("CarControl");
//var motorInput:CarControl = GetComponent("motorInput");
}
function OnMouseDown () {
motorInput = 1;
}

I am trying to get this GUITexture script to change the motorInput in another script. I am thinking I have to do a getcomponant but I have tried that but it still did not seem to work. Here is a picture to help understand what I am saying.

This is the motorInput code from the original, If it helps at all

var motorInput = 0.0;

Would someone please be able to help me out. I don’t know what to do at this point.

I had the same issue.

In my C# script, I made this :

void Start ()
{
GameObject targetMoverObject = GameObject.FindGameObjectWithTag ("Target");
if (targetMoverObject != null)
{
    targetMover = targetMoverObject.GetComponent <TargetMover>();
}
if (targetMover == null)
{
    Debug.Log ("Cannot find 'TargetMover' script");
}
}

void Update ()
{
  targetMover.speed = targetMover.speed + level;
}

The purpose of this script is to increase the speed of the “transform.right”.

We see the scripts, but not the object hierarchy.

  • A component is a script on a specific game object, so unless all these components are on the same game object, you have to identify the game object. GameObject.Find() or GameObject.FindWithTag() are the typical solutions.
  • Use GetComponent() without the quotation marks.

 motorInput = GameObject.Find("SomeObject").GetComponent(CarControl);

…or if it is on the same game object as the script:

      motorInput = GetComponent(CarControl);

http://docs.unity3d.com/412/Documentation/ScriptReference/index.Accessing_Other_Game_Objects.html

http://unitygems.com/script-interaction-tutorial-getcomponent-unityscript/