How to get this 2 c# Scripts together

Hello,

i have a problem to get the Shake(); funktion to call in GUI_file. I get the error : The name `otherScript’ does not exist in the current context but i dont know how to declare, mean declare as what?! and is the code, for the shakewindow, correct? cant get it to work.

  1. Get shakewindow :
using UnityEngine;
using System.Collections;
public class GUI_file : MonoBehaviour {


GameObject[] player;
    public Texture2D hoverTex;
public Texture2D normalTex;
public Transform projectile;
public Transform exp_prefab;
public Vector3 spawnLocation = new Vector3(0,2,0);
public GameObject mine;
public AudioClip explosionClip;
public Rect windowRect = new Rect(20, 20, 253, 357);
GUI.WindowFunction windowFunction;
public bool windowOpen;
public GUISkin customSkin;
public Texture2D aTexture;
public Transform Shake;

void Start()
    {
  Hide();  
    }


// shakewindow holen

void Update() {
        shakewindow otherScript = GetComponent<shakewindow>();
        otherScript.Shake();
    }

void Show(int windowID) {
  windowOpen=true;
}
void OnMouseEnter () {
guiTexture.texture = hoverTex;
}

void OnMouseExit () {
guiTexture.texture = normalTex;
}
IEnumerator OnMouseDown()
{
    player = GameObject.FindGameObjectsWithTag("Player");
    Debug.Log("Mine dropped");
  Show(1);
    GameObject mine = Instantiate(projectile,GameObject.Find("Player").transform.position,Quaternion.identity) as GameObject;
    Destroy(GameObject.Find("mine_prefab(Clone)"),5);
    yield return new WaitForSeconds(4.9f);
    GameObject explosion = Instantiate(exp_prefab,GameObject.Find("mine_prefab(Clone)").transform.position,Quaternion.identity) as GameObject;

// here the shakewindow 
  otherScript.Shake();

  AudioSource.PlayClipAtPoint(explosionClip,GameObject.Find("mine_prefab(Clone)").transform.position);
  yield return new WaitForSeconds(3.0f);
   Debug.Log("was gefunden?");
}

void OnGUI() {
        GUI.skin = customSkin;
  if (windowOpen==true) {
  windowRect = GUI.Window (1, windowRect, DoMyWindow, "");
    }
}

void DoMyWindow(int windowID)
    {
GUI.DrawTexture(new Rect(0, 0, 253, 357), aTexture, ScaleMode.ScaleToFit, true, 0F);
if (GUI.Button (new Rect (230, 0,30, 30), "X")) {
    Hide();  
}
GUI.Label (new Rect (15, 150, 100, 20), "Searching...");
GUI.DragWindow();
}

void Hide() {
windowOpen = false;
}

}

the shake code :

using UnityEngine;
using System.Collections;
public class shakewindow : MonoBehaviour {
public Vector3 originPosition;
public Quaternion originRotation;
public float shake_decay;
public float shake_intensity;

public void Update(){
if(shake_intensity > 0){
transform.position = originPosition + Random.insideUnitSphere * shake_intensity;
transform.rotation = new Quaternion(
originRotation.x + Random.Range(-shake_intensity,shake_intensity)*.2f,
originRotation.y + Random.Range(-shake_intensity,shake_intensity)*.2f,
originRotation.z + Random.Range(-shake_intensity,shake_intensity)*.2f,
originRotation.w + Random.Range(-shake_intensity,shake_intensity)*.2f);
shake_intensity -= shake_decay;
}
}

public void Shake(){
originPosition = transform.position;
originRotation = transform.rotation;
shake_intensity = .3f;
shake_decay = 0.002f;
}
}

ty for help :slight_smile:

What that means is you need to have shakewindow attached to the gameobject you have gui_file attached to. I recommend not making files with underscores though, gives weird errors sometimes.

Got it to work, ty :slight_smile:

I know you got it to work, but I think that before trying to make games you should learn actual game programming or else it will be very diffucult…oh wait…It’s unity, nvm forgot its retard API.