How do i change a bool to true on collide when the bool is on a different script
Self explanatory but here is my scripts. using UnityEngine; using System.Collections; using UnityEngine.Networking;
public class Spawnold3 : MonoBehaviour
{
public GameObject AssaultPlayer;
public GameObject ReconPlayer;
public static bool Support = false;
public static bool Engineer = false;
public GameObject EngineerPlayer;
public static bool tron = false;
public GameObject TronPlayer;
public Transform[] spawnPoints;
public Camera spawnCam;
public AudioListener spawnListener;
public bool spawned = false;
public static Spawnold3 instance;
void Start(){
instance = this;
}
void OnGUI()
{
if (Network.isServer || Network.isClient) {
if (!spawned) {
if (GUI.Button (new Rect (Screen.width / 10 - 50, Screen.height / 10 - 25, 100, 50), "assault")) {
SpawnAssault ();
}
if (Support ==true)
if (GUI.Button (new Rect (Screen.width / 10 - 160, Screen.height / 10 - 25, 100, 50), "support")) {
SpawnSupport ();
}
if (Engineer == true) {
if (GUI.Button (new Rect (Screen.width / 10 - -60, Screen.height / 10 - 25, 100, 50), "Engineer")) {
SpawnEngineer ();
}
if (tron == true) {
if (GUI.Button (new Rect (Screen.width / 10 - -60, Screen.height / 10 - 25, 100, 50), "tron")) {
Spawntron ();
}
}
}
}
}
}
void SpawnSupport()
{
spawned = true;
int random = Random.Range(0, spawnPoints.Length);
Network.Instantiate(ReconPlayer, spawnPoints[random].position, spawnPoints[random].rotation, 0);
spawned = true;
spawnCam.enabled = false;
spawnListener.enabled = false;
spawned = true;
}
void SpawnEngineer()
{
spawned = true;
int random = Random.Range(0, spawnPoints.Length);
Network.Instantiate(EngineerPlayer, spawnPoints[random].position, spawnPoints[random].rotation, 0);
spawned = true;
spawnCam.enabled = false;
spawnListener.enabled = false;
spawned = true;
}
void SpawnAssault()
{
spawned = true;
int random = Random.Range(0, spawnPoints.Length);
Network.Instantiate(AssaultPlayer, spawnPoints[random].position, spawnPoints[random].rotation, 0);
spawned = true;
spawnCam.enabled = false;
spawnListener.enabled = false;
spawned = true;
}
void Spawntron()
{
spawned = true;
int random = Random.Range(0, spawnPoints.Length);
Network.Instantiate(TronPlayer, spawnPoints[random].position, spawnPoints[random].rotation, 0);
spawned = true;
spawnCam.enabled = false;
spawnListener.enabled = false;
spawned = true;
}
public void Die()
{
Screen.lockCursor = false;
spawned = false;
spawnCam.enabled = true;
spawnListener.enabled = true;
}
}
Here is my choos random object and spawn script but i want to make it so the object that spawns has a script to it so that when it collides with something it will change a bool to true. which in my case is a case opener that when it collides it sets the bool to true so you can use that class.
using UnityEngine;
using System.Collections;
public class CaseChooseRandom : MonoBehaviour {
public Transform[] teleport;
public GameObject[] People;
public GameObject[] Explosion;
public void Start(){ //this will spawn only one prefeb, if you want call it many time, create a new function and call it or create for loop
if (CaseOpen.HasCase == true) {
int tele_num = Random.Range (0, 1);
int People_num = Random.Range (0, 1);
int Explosion_num = Random.Range (0, 1);
Instantiate (Explosion [Explosion_num], teleport [tele_num].position, teleport [tele_num].rotation);
Instantiate (People [People_num], teleport [tele_num].position, teleport [tele_num].rotation);
GameObject.Find ("weaponBox").SetActive (false);
CaseOpen.HasCase = false;
if (CaseOpen.HasCase == false) {
GameObject.Find ("UINOCase").SetActive (true);
}
}
}
}
Not exactly. What bool do you want to set to true and from where? Also what problems are you currently having doing this?
I try to change the public static bool but it doesn't do anything. $$anonymous$$Y Gun is ment to spawn and then where it spawns it has a rigidbody and it needs to hit the ground then the bool changes to true
@$$anonymous$$avina Help please its taken me 3 full days
public GameObject ReconPlayer; 5. public static bool Support = false; this is the bool I want to change to true to signal that he can use it because he earned it
Answer by TBruce · May 04, 2016 at 10:29 PM
Remove the static, Instead get a reference to Spawnold3 like this
Spawnold3 spawn = gameObject.GetComponent<Spawnold3>;
spawn.support = true;
Edit: I do not know if this is an option for you but it is a public variable can this be set in the inspector?
Note: Make your non-static varibles lowerCamelCase.
im still confused do I need to make a spawn variable too
What is the collision phrse to say when it collides with this then set bool to true @$$anonymous$$avina
Do you mean
void OnCollisionEnter (Collision col)
{
if(col.gameObject.name == "Player")
{
// do whatever
}
}
or
void OnCollisionEnter (Collision col)
{
if(col.gameObject.tag == "Player")
{
// do whatever
}
}
or
void OnCollisionEnter2D (Collision2D col)
{
if(col.gameObject.name == "Player")
{
// do whatever
}
}
or
void OnCollisionEnter2D (Collision2D col)
{
if(col.gameObject.tag == "Player")
{
// do whatever
}
}
Wow thanks a lot I think you will also help out the other 109 people following this queston
Whats a CamelCase and I cant set static bools in inspector
Check out this link on CamelCase. There are two forms of CamelCase, lowerCamelCase and UpperCamelCase. lowerCamelCase is intended for variables and UpperCamelCase is used for Classes, Namespaces, Function names and static variables.
That is why I said to remove the static, so it could be modified.
@$$anonymous$$avina https://gyazo.com/83fde18ac3eda2d75e03bfde7c185517 how would I fix this error then
Your answer
Follow this Question
Related Questions
UNET with Secure Firewalls 0 Answers
Bullets showing only on host and weapons not appearing 3 Answers
Instantiated Players Transform Not Changing 0 Answers
Unity Scene Editor get bugged on Host lan 0 Answers
Merry Fragmas 3.0 not working on android 0 Answers