Question by
bananaofdeath167 · Feb 08, 2016 at 12:50 PM ·
c#camera
My boolean value won't get called from other script
so I have a problem with my code there is a boolean value in one script that controls whether or not the main game is started here is my code for the two scripts
//First script
//Checks if the laser, this.gameObject has collided with the right game
//object otherwise it will stop the game
using UnityEngine;
using System.Collections;
public class DestroyShotR : MonoBehaviour {
public GameObject contactExpolosion;
public StartGame game;
void OnTriggerEnter (Collider other) {
if (other.tag == "Right") {
//put add score here
Debug.Log ("Add Score");
Destroy (other.gameObject);
Destroy (this.gameObject);
Instantiate (contactExpolosion, other.transform.position, Quaternion.identity);
} else if (other.tag == "Boundary") {
return;
} else {
Debug.Log ("Game Stopping");
Destroy (other.gameObject);
Destroy (this.gameObject);
Instantiate (contactExpolosion, other.transform.position, Quaternion.identity);
game.started = false;
}
}
}
//This uses a on trigger enter event to check if the camera is in the play area
//The bool is used for other scripts to check if the game is started
using UnityEngine;
using System.Collections;
public class StartGame : MonoBehaviour {
public bool started;
public void OnTriggerEnter (Collider other) {
started = true;
}
}
Comment
Asked a friend whom figured out the problem. As it turns out I had to put GameObject.FindWithTag("Insert$$anonymous$$yTagHere").GetComponent(); and set that equal to the game variable to fix it
Your answer
Follow this Question
Related Questions
How do I offset a camera when it's position is defined by a VR controller 0 Answers
Change Camera postion 1 Answer
Take screenshot with no lags Android 0 Answers
Preventing world interactions when using an UI element with an Orthographic 3D camera 0 Answers
Recognize when ever camera looks up and turns back down 0 Answers