Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
avatar image
0
Question by Squeekpro107 · May 04, 2016 at 09:46 PM · unity 5multiplayerunity 4.6

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);
 
             }
         }
     }
 }        


Comment
Add comment · Show 4
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image TBruce · May 04, 2016 at 10:22 PM 0
Share

Not exactly. What bool do you want to set to true and from where? Also what problems are you currently having doing this?

avatar image Squeekpro107 TBruce · May 04, 2016 at 10:24 PM 0
Share

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

avatar image Squeekpro107 Squeekpro107 · May 04, 2016 at 10:25 PM 0
Share

@$$anonymous$$avina Help please its taken me 3 full days

avatar image Squeekpro107 TBruce · May 04, 2016 at 10:30 PM 0
Share

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

2 Replies

· Add your reply
  • Sort: 
avatar image
0
Best Answer

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.

Comment
Add comment · Show 11 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Squeekpro107 · May 04, 2016 at 10:32 PM 0
Share

im still confused do I need to make a spawn variable too

avatar image Squeekpro107 · May 04, 2016 at 10:32 PM 0
Share

I got it doesn't matter

avatar image Squeekpro107 · May 04, 2016 at 10:33 PM 0
Share

What is the collision phrse to say when it collides with this then set bool to true @$$anonymous$$avina

avatar image TBruce Squeekpro107 · May 04, 2016 at 10:45 PM 0
Share

@Squeekpro107

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
     }
 }
avatar image Squeekpro107 TBruce · May 04, 2016 at 11:02 PM 0
Share

Wow thanks a lot I think you will also help out the other 109 people following this queston

avatar image Squeekpro107 · May 04, 2016 at 10:36 PM 0
Share

Whats a CamelCase and I cant set static bools in inspector

avatar image TBruce Squeekpro107 · May 04, 2016 at 10:58 PM 0
Share

@Squeekpro107

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.

avatar image Squeekpro107 TBruce · May 04, 2016 at 11:09 PM 0
Share

@$$anonymous$$avina https://gyazo.com/83fde18ac3eda2d75e03bfde7c185517 how would I fix this error then

Show more comments
avatar image
0

Answer by Squeekpro107 · May 04, 2016 at 10:37 PM

@MAVINA ANSWER PLEASE

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

103 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

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


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges