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 $$anonymous$$ · Nov 13, 2013 at 10:22 PM · collisioncollidertriggermeleeoncollisionstay

OnCollisionStay melee

Script:

function Update(){

}

function OnCollisionStay (col : Collider){ if(Input.GetButtonDown("Fire1")){ Destroy.this.gameObject; } } End of Script


I am still pretty bad at coding, so can someone help me? The goal of this is to get a cube that will be invisible as a colliding trigger. I am not fighting enemy AI's with this code, but rather I need this to break in game objects like in minecraft.

Thanks for the help!

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 $$anonymous$$ · Nov 13, 2013 at 11:10 PM 0
Share

Oh, and I need the game objects to have a mesh collider so I cant make the actual objects that are being destroyed a trigger or else it wont have collision. That means that the actual trigger needs to the one that is attached to the player cam.

avatar image Dracorat · Nov 13, 2013 at 11:11 PM 0
Share

Please use "Add New Comment" to add comments - not "Post an Answer"

avatar image $$anonymous$$ · Nov 13, 2013 at 11:14 PM 0
Share

sorry I'm new like I said

avatar image rednax20 · Nov 14, 2013 at 09:05 PM 0
Share

Disabiling the mesh renderer would not stop collisions. It would just make the object invisible. Disabling the box collider, (or the rigibody in some cases) would disable collisions

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by rednax20 · Nov 13, 2013 at 10:35 PM

First, please spell out your problem. Second, format your code.

I noticed a few possible problems in your question because you didn't make it clear i will just try to answer them all, (I need something to do right now anyway. )

  1. invisible cube, if that was your problem then uncheck the mesh renderer component

  2. to make the cube follow you make it a child of your character

  3. change Destroy.this.gameObject to Destroy(col.gameObject)

I think that's everything. Sorry i was a little harsh at the top of my answer. I know how tough it is to be just starting out with Unity. good luck solving your problem. I hope this help.

Quishtay™ all the way

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 $$anonymous$$ · Nov 13, 2013 at 11:02 PM 0
Share

Thanks for the input! I have a cube that is attached to the main camera on my char controller with the tag "Attack" attached to it.

  1. I need to destroy any game object in the "Attack area"

  2. It need shouldn't work on the ground or anything else I could tag "DontBreak" or something like that

This is the script now. Script:


function Update(){

}

function OnCollisionStay (col : Collision){

 if(col.gameObject.tag == "Attack"){

     if(Input.GetButtonDown("Fire1")){ 

         Destroy(col.gameObject); 

     }

  }


}

avatar image rednax20 · Nov 14, 2013 at 09:02 PM 0
Share

so have you solved your problem? is there anything else you need?

avatar image Barachiel · Nov 14, 2013 at 09:25 PM 0
Share

Wait, is that script attached to the trigger you have following your character? If so, from what I understand so far, you're telling your trigger (with the "Attack" tag) to destroy other things with the "Attack" tag. If so, you'd need to tag all your destroyable blocks rather than your trigger.

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

18 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

Related Questions

Trigger Spawning? 1 Answer

Can't click gameobject when over another trigger? 1 Answer

Colliding two GameObjects 1 Answer

OnTriggerEnter is not running! Need help with collision. 2 Answers

Trigger on OnCollisionEnter 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