- Home /
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!
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.
Please use "Add New Comment" to add comments - not "Post an Answer"
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
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. )
invisible cube, if that was your problem then uncheck the mesh renderer component
to make the cube follow you make it a child of your character
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
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.
I need to destroy any game object in the "Attack area"
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);
}
}
}
so have you solved your problem? is there anything else you need?
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
Follow this Question
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