Scripts in scripts

hi,

I’m currently making a button class for the GUI of my game, everything pretty much sorted but I am trying to link another script (the button action) to the button script that is only ran when the button registers a click. The problem I have is constructing a public variable to store the (button action) script. I had an idea of using a ‘GameObject’ to store it but how would I then activate the script?

Thank you in advance

Hey hursty90 :D, I’ll be more than happy to help you do you think you could post a tad bit of code so I could see how your button class is set up? I think even with out seeing your code what you want to do is drag the gameobject that contains the (button action) script in the the onto the buttons public variable (button action) in the inspector.

Something like this should be declared in your button class.

using UnityEngine;
using System.Collections;

public class Button : MonoBehaviour
{ 
// Public Variables 
public string Text; 
// Text content for the button 
public Vector2 Position; 
// X & Y public 
Vector2 Size; 
// Width & Heigh

public GUIContent ButtonContent;
public GUIStyle ButtonStyle;
public string ScriptName;

// Private Vriables
private Rect mColisionBox; // Used to check mouse collisions
private Component ScriptRef;

public ActionButtonScript buttonScript;

// Constructor
void Start()
{
    // Construct collision box
    mColisionBox.xMin = Position.x;
    mColisionBox.yMin = Position.y;
    mColisionBox.xMax = Size.x;
    mColisionBox.yMax = Size.y;

    ScriptRef = gameObject.GetComponent(ScriptName);

    buttonScript = FindObjectOfType(typeof(ActionButtonScript)) as ActionButtonScript;
}

void Update()
{
    if (GUI.Button(mColisionBox, ButtonContent, ButtonStyle))
    {
        buttonScript.<insert fucntion here>
    }
}

// Private Functions

};

Then in the inspector you’d be able to drag any game object with a button action script into that public variable.

Seeing you code I’d be able to help a lot more.

But I hope this at least helps a little bit.

Hans