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 /
avatar image
0
Question by VCorder · Apr 25, 2017 at 05:04 AM · collisiongameobjectgame

How to make a gameObject active triggered by a collision of another?

I'm trying to get Flower4 game object to become active after the player rolls over Flower3.

 void OnCollisionEnter (Collision my_collision){
         //print ("Collided with " + my_collision.collider.name);
         if (my_collision.gameObject.name == "Bee") {
             Debug.Log ("I'm A Bee!!");
         }
 
     
         if (my_collision.gameObject.name == "Flower1") {
             UnityEngine.SceneManagement.SceneManager.LoadScene ("Level_Two");
         }
         if (my_collision.gameObject.name == "Flower2") {
             UnityEngine.SceneManagement.SceneManager.LoadScene ("Level_Three");
 
 
             if (my_collision.gameObject.name == "Flower3") {
                 (my_collision.collider.name == "Flower3"){ 
                     gameObject.SetActive(true)}
             
                     
                 //if (my_collision.gameObject.name == "Flower4") {
                 //UnityEngine.SceneManagement.SceneManager.LoadScene ("Level_Four");}
 
             }
         }
     }
 
Comment
Add comment · Show 1
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 SohailBukhari · Apr 25, 2017 at 07:26 AM 0
Share

$$anonymous$$ake unity Event and invoke event when player rolls over Flower3 and in his listener make gameObject active.

1 Reply

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

Answer by StrawberryJellyfish · Apr 25, 2017 at 10:25 AM

I'm supposing that you logic making Flower 4 active is Line 15-17? Because if it is, it doesn't make much sense to me. Typing gameObject.SetActive(true) just enables the object that this script is attatched to.

I would suggest making a public variable flowerFour for Flower 4 and using this code

 if (my_collision.gameObject.name == "Flower3") {
             flowerFour.SetActve(true);   
 }

Comment
Add comment · Show 4 · 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 VCorder · Apr 26, 2017 at 04:04 AM 0
Share

I'm really new to Unity and I'm a bit confused on what to do. If you meant like this:

 public class Collide : $$anonymous$$onoBehaviour {
     public class  flowerFour{
 
 
     void OnCollisionEnter (Collision my_collision){
 
         //print ("Collided with " + my_collision.collider.name);
         if (my_collision.gameObject.name == "Bee") {
             Debug.Log ("bee hit the orange flower");
         }
 
     
         if (my_collision.gameObject.name == "Flower1") {
             UnityEngine.Scene$$anonymous$$anagement.Scene$$anonymous$$anager.LoadScene ("Level_Two");
         }
         if (my_collision.gameObject.name == "Flower2") {
             UnityEngine.Scene$$anonymous$$anagement.Scene$$anonymous$$anager.LoadScene ("Level_Three");
 
 
             if (my_collision.gameObject.name == "Flower3") {
                 flowerFour.SetActve(true);   
             }
 
             
                     
                 if (my_collision.gameObject.name == "Flower4") {
                 UnityEngine.Scene$$anonymous$$anagement.Scene$$anonymous$$anager.LoadScene ("Level_Four");}
 
 
         }
 
     }
 }
 }
 



Then it's not working.

avatar image StrawberryJellyfish VCorder · Apr 26, 2017 at 08:01 AM 0
Share

No no, flowerFour is meant to be a variable.

 public class Collide : $$anonymous$$onoBehaviour {
 
      public GameObject flowerFour;
  
  
      void OnCollisionEnter (Collision my_collision){
  
          //print ("Collided with " + my_collision.collider.name);
          if (my_collision.gameObject.name == "Bee") {
              Debug.Log ("bee hit the orange flower");
          }
  
      
          if (my_collision.gameObject.name == "Flower1") {
              UnityEngine.Scene$$anonymous$$anagement.Scene$$anonymous$$anager.LoadScene ("Level_Two");
          }
          if (my_collision.gameObject.name == "Flower2") {
              UnityEngine.Scene$$anonymous$$anagement.Scene$$anonymous$$anager.LoadScene ("Level_Three");
  
  
              if (my_collision.gameObject.name == "Flower3") {
                  flowerFour.SetActve(true);   
              }
  
              
                      
                  if (my_collision.gameObject.name == "Flower4") {
                  UnityEngine.Scene$$anonymous$$anagement.Scene$$anonymous$$anager.LoadScene ("Level_Four");}
  
  
          }
  
      }
  }
  

Then, In the Inspector, you drag and drop the Flower 4 gameObject into the slot that will be created in that script component.

avatar image VCorder StrawberryJellyfish · Apr 26, 2017 at 10:13 AM 0
Share

Okay I tried that and it didn't work it seems.

 public GameObject flowerFour;
 
 
     void OnCollisionEnter (Collision my_collision){
 
         //print ("Collided with " + my_collision.collider.name);
         if (my_collision.gameObject.name == "Bee") {
             Debug.Log ("bee hit the orange flower");
         }
 
 
         if (my_collision.gameObject.name == "Flower1") {
             UnityEngine.Scene$$anonymous$$anagement.Scene$$anonymous$$anager.LoadScene ("Level_Two");
         }
         if (my_collision.gameObject.name == "Flower2") {
             UnityEngine.Scene$$anonymous$$anagement.Scene$$anonymous$$anager.LoadScene ("Level_Three");
 
 
             if (my_collision.gameObject.name == "Flower3") {
                 flowerFour.SetActive(true);  
             }
 
 
 
             if (my_collision.gameObject.name == "Flower4") {
                 UnityEngine.Scene$$anonymous$$anagement.Scene$$anonymous$$anager.LoadScene ("Level_Four");}
 
 
         }

alt text

screen-shot-2017-04-26-at-51057-am.png (29.1 kB)
Show more comments

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

OnTriggerEnter not working, tried everything! :( (C#) 3 Answers

Why do Instantiated GameObjects Colliders only work on player i am controlling,nothing else? 2 Answers

How to stop Camera from going into colliders 3 Answers

Create A Counter And GameObjects Unique ID 1 Answer

[SCRIPTERS] Im making a building game with a system like Gmod 2 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