Hi, I have to cameras, camera A and Camera b, Camera 1 is the player camera and camera 2 is set to a minni game that it only trigged when you click on a "ghost, it dissables player camera enabmes ghost camera and enables ghost minigame script,
no errors, but canot seem to use static Public camera,
when i need it to be in inspector and to be a static to call from another script.
Code A
using UnityEngine;
using System.Collections;
public class GhostSteets : MonoBehaviour
{
static public Camera camera;
static public Camera camera2;
public RaycastHit hit = new RaycastHit();
public Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
void Update() {
if(Input.GetKeyDown(KeyCode.Mouse0)) {
// Set or reset ray here
ray = Camera.main.ScreenPointToRay(Input.mousePosition);
if(Physics.Raycast(ray, out hit)) {
camera.enabled = !camera.enabled;
camera2.enabled = !camera2.enabled;
}
}
}
}
Code B:
public class GhostsStreetsMiniGame : MonoBehaviour
{
static public Camera camera;
static public Camera camera2;
// ghost streets minigame,
//3 chances to find the ghost or it vanishes for 5 minutes
float timeLimit = 180.0f; // Timer set for 3 minutes to complete challange.
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update()
{
// translate object for 10 seconds.
if(timeLimit > 1) {
// Decrease timeLimit.
timeLimit -= Time.deltaTime;
// translate backward.
transform.Translate(Vector3.back * Time.deltaTime, Space.World);
Debug.Log(timeLimit); }
// if out of time,
if (timeLimit < 1 )
{
camera.enabled = true;
camera2.enabled = false;
}
}
// End Of Update;
void OnGUI ()
{
if (GhostSteets.camera2.enabled = true); // if a ghost street scene is initiated...
{
GUI.color = Color.white; // Set Time Color
GUI.Label( new Rect (50,300,80,20), "Clock"+timeLimit); // Display Timer Limit
GUI.Label( new Rect (150,300,80,20), "Find The Hidden Ghost!"); // Display Timer Limit
GUI.color = Color.blue; // Set Hidden ghost buttons
// Draw Otion for where ghost myght be hidding X5 Buttons.
GUI.Button( new Rect (100,700,30,30), "?");
{
GhostChance ();
}
}
}
// after box is clicked, run chance of ghost being hidden their.
void GhostChance ()
{
int num = Random.Range(7,25); // 7 .. 24 since 25 is exclusive.
if (num > 15){
Debug.Log("WEll done!");
global.XP += +10; //Get +10 XP from the quest.
global.usergold += +5; // gain bonous +5 gold
if (GhostSteets.camera2.enabled = true);
{
enablecamera ();
}
}
}
////***************** End Of Ghost Chance ************************
void enablecamera () {
if(GhostSteets.camera2.enabled = !GhostSteets.camera2.enabled);
if(GhostSteets.camera.enabled = !GhostSteets.camera.enabled);
}
}