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 DougAllen · Sep 04, 2018 at 01:23 PM · collisioncollidersboolaccessing from any script

How to check if an object has collided from another script?

 public bool touchCheck;
 private bool self;
 private bool notSelf;


 void OnTriggerEnter(Collider other) {

     if (other.gameObject.tag == "Piece") {

         if (other.transform == gameObject.transform.parent) {
             self = true;
         } else if (other.transform != gameObject.transform.parent) {
             notSelf = true;
         }

         if (self && notSelf) {
             touchCheck = true;
             Debug.Log ("Pieces touch!");
         }
     }
 }

The above is the "TouchCheck" script attached to a child object, checking if it collides with it's parent and another object at the same time. This script works. My problem is this: I want a separate script "RoomGen" to tell me what "TouchChecks" value is. When I get to the point in my "RoomGen" script that asks whether there is a collision before it spawns another piece, it's value will NEVER return true despite the "TouchCheck" collision script saying there has been a collision.

I would appreciate any help as I haven't been able to figure this out for two days.

 public GameObject Piece01, Piece02, Piece03, Piece04, Piece05, Piece06, Piece07, Piece08, Piece09; 
 private GameObject nextSpawnObj;
 private GameObject spawnObject;
 GameObject touchCheckObj;

 public int maxPieces;
 int spawnCount;
 int rndPieceSpawn;
 Vector3 nextSpawnPos;
 Quaternion nextSpawnRotation;


 void Start () {
     
     nextSpawnPos = Vector3.zero;
     nextSpawnRotation = new Quaternion();
 }

 void Update () {

     if (spawnCount != maxPieces) {
         
         rndPieceSpawn = Random.Range (1, 10);

         switch (rndPieceSpawn) {
         case 1:
             spawnObject = Piece01;
             break;
         case 2:
             spawnObject = Piece02;
             break;
         case 3:
             spawnObject = Piece03;
             break;
         case 4:
             spawnObject = Piece04;
             break;
         case 5:
             spawnObject = Piece05;
             break;
         case 6:
             spawnObject = Piece06;
             break;
         case 7:
             spawnObject = Piece07;
             break;
         case 8:
             spawnObject = Piece08;
             break;
         case 9:
             spawnObject = Piece09;
             break;
         }

         SpawnObj (spawnObject);

         touchCheckObj = GameObject.Find("touchCheck");
         TouchCheck touchCheckScript = touchCheckObj.GetComponent<TouchCheck>();
         bool check = touchCheckScript.touchCheck;
             
         if (check == true) {
             Debug.Log ("Pieces touch! - RoomGen");
         }

         if (check == false) { 
         FindNewSpawnPos ("nextObjSpawnPoint");
         FindNewSpawnRota ("nextObjSpawnPoint");
         Destroy (touchCheckObj.gameObject);
         spawnCount += 1;
     }
             
 }
     

}

 private void SpawnObj(GameObject Obj) {

     GameObject.Instantiate (Obj,nextSpawnPos, nextSpawnRotation);
 }

 public void FindNewSpawnPos (string nextObjSpawnPoint) {
     
     nextSpawnObj = GameObject.Find (nextObjSpawnPoint);
     nextSpawnPos = nextSpawnObj.transform.position;
 }

 public void FindNewSpawnRota (string nextObjSpawnPoint) {

     nextSpawnObj = GameObject.Find (nextObjSpawnPoint);
     nextSpawnRotation = nextSpawnObj.transform.rotation;
     Destroy (nextSpawnObj);
 }
Comment
Add comment
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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Rynbernsz · Sep 04, 2018 at 07:03 PM

In your RoomGen, create a TouchCheck object, something like this.

 TouchCheck check;
 
 void Start() {
 
      // Sets check object to touchCheck boolean 
      check = GameObject<TouchCheck>().touchCheck;
 }
 
 void Update() {
      // Use touchCheck boolean
      if (touchCheck) {
           
           // Do this if touchCheck is TRUE
      } else {
 
           // Do this instead if touchCheck is FALSE
      }
 }

I don't know if this is most optimal, but this is what I do usually. Let me know if that works! :)

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

204 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 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

Need a simple health script 1 Answer

How i prevent 2 obejcts with kinematic checked in both rigidbodies collide? 3 Answers

How to check if gameObject is interact with multiple colliders 1 Answer

player going through walls even though it has colliders and rigidbodies 0 Answers

How do I detect a collision between two objects using Bolt? 1 Answer


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