Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 Ketwuns · Apr 11, 2014 at 08:09 AM · collisiongameobjecttagsetactivefalse

I want ball to be invisible after colliding with goals?

So I have a game where the main idea is to get balls into goals. In one level, there are soccer goals all around. The balls need to disappear when they get in the nets. I have used a script called "Score" in C#, attached to the ball object and tried DestroyObject(gameobject) as that would make the balls disappear. However, I found it doesn't always do it, especially after you restart the level. and does not seem like people online like people destroying objects like so. For my game, these balls do not need to respawn. Once they are gone, they are gone. Just restarting the level where everything resets, but that's already done for me somewhere else. So here is what I had.

 void OnCollisionEnter(Collision collision)
 {
     if(collision.gameObject.name == "Goalposts" || collision.gameObject.name == "FootyGoals" ||
            collision.gameObject.name == "GoalCollider" || collision.gameObject.name == "Goal ring") 
             
     {
 Destroy (this.gameObject);

//I understand what gameobject.SetActive(false) could do, but it wouldn't do the similar idea of making it invisible. } }

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 ahaykal · Apr 11, 2014 at 08:26 AM 0
Share

What do you mean it isn't destroying objects when restarting the level? How are you restarting the level? how come sometimes it destroys and other times no? $$anonymous$$aybe it's not colliding that is why it's not destroying? Question is too vague to be able to help you.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Salzmann · Apr 11, 2014 at 09:39 AM

Hey, this will help you make the ball invisible - I don't know if this will help, if it doesn't, give me feedback and I will try to think of something else.

The ball has a material. You can manipulate the color of the material with code. However, in order to manipulate the alpha of the material, the shader has to be of the transparent type. Just click on the material that all your balls have and click on the drop down box, there you can choose the type "Transparent" and in there you can choose the same type your shader had been. Once that is done, you can change the alpha by accessing the material's color like so:

 GetComponent<MeshRenderer>().material.color = new Color(GetComponent<MeshRenderer>().material.color.r,
                                                         GetComponent<MeshRenderer>().material.color.g,
                                                         GetComponent<MeshRenderer>().material.color.b,
                                                         GetComponent<MeshRenderer>().material.color.a);

You can set the color then - including the new alpha. The alpha is the 4th number in the Color() constructor and it is a float between 0 and 1.

Comment
Add comment · Show 3 · 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 Ketwuns · Apr 14, 2014 at 04:16 AM 0
Share

It's supposed to not be touchable though. Transparency still could cause the ball to be collidable, and accidently collide with the car or other objects, causing unwarranted bugs. The ball has to disappear and be destroyed safely. $$anonymous$$aybe just better off giving a way to destroy it. Sorry. I should have explained it needs to disappear by being inactive. But I tried setActive(false) and it doesn't do it, but Destroy does, but only half the time...

avatar image Salzmann · Apr 14, 2014 at 08:11 AM 0
Share

In that case it is probably a bug in your code. Destroy() is reliable.

avatar image Ketwuns · Apr 15, 2014 at 05:42 AM 0
Share

I have to send the entire thing to get anywhere don't I? Never $$anonymous$$d.

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

24 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

Related Questions

gameObject.name for more then one object? 1 Answer

Problems with save 1 Answer

Collision problem 2 Answers

Is CompareTag faster than checking directly the GameObject? 1 Answer

How to effect a few gameobjects with the same tag through code?,How to affect multiple GameObjects with the same tag through code? 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