I’m making an FPS game, and I want to make a script for my character to tell the weapons to hide if they’re not the current weapon, and hide if they’re not. I created a script for it, I want the weapon scripts to get values from it.
How would I do this?
Also, this is kind of related, is there any way to tell the entire game stuff like what menu or game mode it should be on, or whether or not it’s in demo mode or the full game? Would I have to create a main script for the others to reference?
I figured it out, the script reference didn’t work for me, so I just set them as public and drag and dropped the code into the slot in the inspector, probably not the best way to do it, but it works!
I hope this is actualy what you need it’s very basic but it shows you how to refference from 1 script to another.
//script 1
using UnityEngine;
using System.Collections;
public class TestFile1 : MonoBehaviour {
public int SomeNumber = 1;
public static TestFile1 main;
void Awake ()
{
main = this;
}
}
//Script 2
using UnityEngine;
using System.Collections;
public class TestFile2 : MonoBehaviour {
// Use this for initialization
void Start ()
{
TestFile1.main.SomeNumber = 2;
}
}
I hope it helps you.